<commit_before>#import "SpecHelper+App.h"
#import "ImagePickerProvider.h"

using namespace Cedar::Matchers;
using namespace Cedar::Doubles;

static UIImagePickerControllerSourceType __sourceType;

@interface UIImagePickerController (Spec)

+ (BOOL)specIsSourceTypeAvailable:(UIImagePickerControllerSourceType)sourceType;

@end

@implementation UIImagePickerController (Spec)

+ (BOOL)specIsSourceTypeAvailable:(UIImagePickerControllerSourceType)sourceType
{
    return sourceType == __sourceType;
}

@end

SPEC_BEGIN(ImagePickerProviderSpec)

describe(@"ImagePickerProvider", ^{
    __block ImagePickerProvider *subject;

    beforeEach(^{
        [UIImagePickerController redirectClassSelector:@selector(isSourceTypeAvailable:)
                                                    to:@selector(specIsSourceTypeAvailable:)
                                         andRenameItTo:@selector(originalIsSourceTypeAvailable:)];
    });

    afterEach(^{
        [UIImagePickerController redirectClassSelector:@selector(isSourceTypeAvailable:)
                                                    to:@selector(originalIsSourceTypeAvailable:)
                                         andRenameItTo:@selector(specIsSourceTypeAvailable:)];
    });


    context(@"when a camera is available", ^{
        beforeEach(^{
            __sourceType = UIImagePickerControllerSourceTypeCamera;
            subject = [[[ImagePickerProvider alloc] init] autorelease];
        });

        it(@"has the correct buttonTitle", ^{
            subject.buttonTitle should equal(@"Take a Photo");
        });

        it(@"should have the correct imagePickerSourceType", ^{
            subject.picker.sourceType should equal(UIImagePickerControllerSourceTypeCamera);
        });

    });

    context(@"when a camera is not available", ^{
        beforeEach(^{
            __sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            subject = [[[ImagePickerProvider alloc] init] autorelease];
        });

        it(@"has the correct buttonTitle", ^{
            subject.buttonTitle should equal(@"Select a Photo");
        });

        it(@"should have the correct imagePickerSourceType", ^{
            subject.picker.sourceType should equal(UIImagePickerControllerSourceTypePhotoLibrary);
        });

    });
});

SPEC_END<commit_msg>Refactored ImagePickerProvider specs.<commit_after>#import "SpecHelper+App.h"
#import "ImagePickerProvider.h"

using namespace Cedar::Matchers;
using namespace Cedar::Doubles;

static UIImagePickerControllerSourceType __sourceType;

@interface UIImagePickerController (Spec)

+ (BOOL)specIsSourceTypeAvailable:(UIImagePickerControllerSourceType)sourceType;

@end

@implementation UIImagePickerController (Spec)

+ (BOOL)specIsSourceTypeAvailable:(UIImagePickerControllerSourceType)sourceType
{
    return sourceType == __sourceType;
}

@end

SPEC_BEGIN(ImagePickerProviderSpec)

describe(@"ImagePickerProvider", ^{
    __block ImagePickerProvider *subject;

    beforeEach(^{
        [UIImagePickerController redirectClassSelector:@selector(isSourceTypeAvailable:)
                                                    to:@selector(specIsSourceTypeAvailable:)
                                         andRenameItTo:@selector(originalIsSourceTypeAvailable:)];
    });

    afterEach(^{
        [UIImagePickerController redirectClassSelector:@selector(isSourceTypeAvailable:)
                                                    to:@selector(originalIsSourceTypeAvailable:)
                                         andRenameItTo:@selector(specIsSourceTypeAvailable:)];
    });

    void (^imagePickerProviderDetectsCameraAvailability)(UIImagePickerControllerSourceType, NSString *) = ^(UIImagePickerControllerSourceType sourceType, NSString *buttonTitle){
        beforeEach(^{
            __sourceType = sourceType;
            subject = [[[ImagePickerProvider alloc] init] autorelease];
        });

        it(@"has the correct buttonTitle", ^{
            subject.buttonTitle should equal(buttonTitle);
        });

        it(@"should have the correct imagePickerSourceType", ^{
            subject.picker.sourceType should equal(sourceType);
        });
    };

    context(@"when there is a camera", ^{
        imagePickerProviderDetectsCameraAvailability(UIImagePickerControllerSourceTypeCamera, @"Take a Photo");
    });

    context(@"when there is not a camera", ^{
        imagePickerProviderDetectsCameraAvailability(UIImagePickerControllerSourceTypePhotoLibrary, @"Select a Photo");
    });
});

SPEC_END
{'fraction_non_alphanumeric': 0.09389464403791051, 'fraction_numerical': 0.0, 'mean_word_length': 3.1442922374429223, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4547081', 'n_tokens_mistral': 1125, 'n_tokens_neox': 1048, 'n_words': 195}