<commit_before>import Quick
import Nimble
import OHHTTPStubs

@testable import Clappr

class UIImageViewTests: QuickSpec {
    override func spec() {
        describe("#UIImageViewTests") {
            describe("get image from url") {
                beforeEach {
                    OHHTTPStubs.removeAllStubs()
                }

                context("when the response is 200") {
                    beforeEach {
                        stub(condition: isExtension("png") && isHost("test200")) { _ in
                            let image = UIImage(named: "poster", in: Bundle(for: UIImageViewTests.self), compatibleWith: nil)!
                            let data = UIImagePNGRepresentation(image)
                            return OHHTTPStubsResponse(data: data!, statusCode: 200, headers: ["Content-Type":"image/jpeg"])
                        }
                    }

                    it("sets image") {
                        let url = URL(string: "https://test200/poster.png")
                        let imageView = UIImageView()

                        imageView.setImage(from: url!)

                        expect(imageView.image).toEventuallyNot(beNil())
                    }
                }

                context("when the response is different of 200") {
                    beforeEach {
                        stub(condition: isExtension("png") && isHost("test400")) { _ in
                            return OHHTTPStubsResponse(data: Data(), statusCode: 400, headers: [:])
                        }
                    }

                    it("doesn't set image") {
                        let url = URL(string: "https://test400/poster.png")
                        let imageView = UIImageView()

                        imageView.setImage(from: url!)

                        expect(imageView.image).toEventually(beNil())
                    }
                }
            }
        }
    }
}
<commit_msg>refact: renaming var and adjusting expect<commit_after>import Quick
import Nimble
import OHHTTPStubs

@testable import Clappr

class UIImageViewTests: QuickSpec {
    override func spec() {
        describe("#UIImageViewTests") {
            describe("get image from url") {
                beforeEach {
                    OHHTTPStubs.removeAllStubs()
                }

                context("when the response is 200") {
                    beforeEach {
                        stub(condition: isExtension("png") && isHost("test200")) { _ in
                            let image = UIImage(named: "poster", in: Bundle(for: UIImageViewTests.self), compatibleWith: nil)!
                            let data = UIImagePNGRepresentation(image)
                            return OHHTTPStubsResponse(data: data!, statusCode: 200, headers: ["Content-Type":"image/jpeg"])
                        }
                    }

                    it("sets image") {
                        let url = URL(string: "https://test200/poster.png")
                        let imageView = UIImageView()

                        imageView.setImage(from: url!)

                        expect(imageView.image).toEventuallyNot(beNil())
                    }
                }

                context("when the response is different of 200") {
                    beforeEach {
                        stub(condition: isExtension("png") && isHost("test400")) { _ in
                            return OHHTTPStubsResponse(data: Data(), statusCode: 400, headers: [:])
                        }
                    }

                    it("doesn't set image") {
                        let url = URL(string: "https://test400/poster.png")
                        let imageView = UIImageView()

                        imageView.setImage(from: url!)

                        expect(imageView.image).toEventually(beNil())
                    }
                }

                context("when repeat the same request") {
                    var requestCount: Int!

                    beforeEach {
                        requestCount = 0

                        stub(condition: isExtension("png") && isHost("test.io")) { _ in
                            requestCount += 1
                            let image = UIImage(named: "poster", in: Bundle(for: UIImageViewTests.self), compatibleWith: nil)!
                            let data = UIImagePNGRepresentation(image)
                            return OHHTTPStubsResponse(data: data!, statusCode: 200, headers: ["Content-Type":"image/jpeg"])
                        }
                    }

                    it("uses image from cache") {
                        let url = URL(string: "https://test.io/poster.png")
                        let imageView = UIImageView()

                        imageView.setImage(from: url!)
                        expect(imageView.image).toEventuallyNot(beNil())
                        imageView.setImage(from: url!)

                        expect(requestCount).to(equal(1))
                    }
                }
            }
        }
    }
}

{'fraction_non_alphanumeric': 0.09662122110254891, 'fraction_numerical': 0.01066982809721399, 'mean_word_length': 1.18095648427402, 'pattern_counts': {'":': 3, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 5, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5310617', 'n_tokens_mistral': 1290, 'n_tokens_neox': 1134, 'n_words': 246}