{"action":"created","comment":{"url":"https://api.github.com/repos/jbender/motion-spec/pulls/comments/49130909","id":49130909,"diff_hunk":"@@ -0,0 +1,221 @@\n+# -*- encoding : utf-8 -*-\n+describe 'MotionSpec::Mock' do\n+  # Test class for mocking.\n+  class Dog\n+    def self.create\n+      new\n+    end\n+\n+    def self.kind\n+      'Mammal'\n+    end\n+\n+    def bark\n+      \"Woof!\"\n+    end\n+\n+    def eat(food)\n+      \"#{food}! Yum!\"\n+    end\n+\n+    # Calls the given block on the nearest toy, a stuffed mouse.\n+    def get_toy(&block)\n+      block.call(\"stuffed mouse\")\n+    end\n+\n+    # Calls the given block on true (for a succesful fetch) and 2 (the time it\n+    # took to fetch.\n+    def fetch(&block)\n+      block.call(true, 20)\n+    end\n+  end\n+\n+  before { @dog = Dog.new }\n+\n+  describe \"#stub!\" do\n+    it \"should stub a class method\" do\n+      Dog.stub!(:thing, return: :thing)\n+      Dog.should.not.be.nil\n+      Dog.thing.should == :thing\n+    end\n+\n+    it \"should stub an instance method\" do\n+      my_obj = Object.new\n+      my_obj.stub!(:hello, return: \"hi\")\n+      my_obj.hello.should.be == \"hi\"\n+    end\n+\n+    it \"should stub using block\" do\n+      my_obj = Object.new\n+      my_obj.stub!(:hello) do |a, b|\n+        a.should == \"foo\"\n+        b.should == \"bar\"\n+        \"#{a},#{b}\"\n+      end\n+      my_obj.hello(\"foo\", \"bar\").should.be == \"foo,bar\"\n+    end\n+  end\n+\n+  describe \"#stub\" do\n+    it \"should create a pure stub\" do\n+      my_stub = stub(:thing, return: \"dude, a thing!\")\n+      my_stub.thing.should == \"dude, a thing!\"\n+    end\n+\n+    it \"should create a stub using block\" do\n+      my_stub = stub(:thing) do |a, b|\n+        a.should == \"a\"\n+        b.should == \"thing!\"\n+        \"dude, #{a} #{b}\"\n+      end\n+      my_stub.thing(\"a\", \"thing!\").should == \"dude, a thing!\"\n+    end\n+  end\n+\n+  describe \"#mock!\" do\n+    it \"should mock an instance method on an object\" do\n+      @dog.mock!(:bark, return: \"Meow!\")\n+      @dog.mock!(:eat, return: \"Yuck!\")\n+      @dog.bark.should == \"Meow!\"\n+      @dog.eat(\"broccoli\").should == \"Yuck!\"\n+    end\n+\n+    it \"should mock using block\" do\n+      @dog.mock!(:bark) do |a|\n+        a.should == \"Meow!\"\n+        a\n+      end\n+      @dog.bark(\"Meow!\").should == \"Meow!\"\n+    end\n+\n+    it \"should mock a class method\" do\n+      Dog.mock!(:create, return: \"Dog\")\n+      Dog.create.should == \"Dog\"\n+    end\n+\n+    it \"should be able to yield a single object\" do\n+      @dog.mock!(:get_toy, yield: \"stuffed fox\")\n+      @dog.get_toy do |toy|\n+        toy.should.be == \"stuffed fox\"\n+      end\n+    end\n+\n+    it \"should be able to yield multiple objects\" do\n+      @dog.mock!(:fetch, yield: [false, 10])\n+      @dog.fetch do |success, time|\n+        success.should.be == success\n+        time.should.be == 10\n+      end\n+    end\n+\n+    it \"should be able to yield the boolean value false\" do\n+      @dog.mock!(:get_toy, yield: false)\n+      @dog.get_toy do |toy|\n+        toy.should.be == false\n+      end\n+    end\n+\n+  end\n+\n+  describe \"#mock\" do\n+    it \"should create pure mock\" do\n+      my_mock = mock(:hello, return: \"hi\")\n+      my_mock.hello.should == \"hi\"\n+    end\n+  end\n+\n+  describe \"#should_not_call\" do\n+    it \"should raise an error with an instance method\" do\n+      @dog.should_not_call(:bark)\n+      should.raise(MotionSpec::Error) do\n+        @dog.bark\n+      end\n+    end\n+\n+    it \"should succeed if the call is not made\" do\n+      should.not.raise(MotionSpec::Error) do\n+        @dog.should_not_call(:bark)\n+      end\n+    end\n+\n+    it \"should not fail in another test\" do\n+      should.not.raise(MotionSpec::Error) do\n+        @dog.bark\n+      end\n+    end\n+\n+    it \"should raise an error with a class method\" do\n+      Dog.should_not_call(:create)\n+      should.raise(MotionSpec::Error) do\n+        Dog.create\n+      end\n+    end\n+  end\n+\n+  describe \"#reset\" do\n+    describe \"stubbing\" do\n+      it \"should restore original class method\" do\n+        Dog.stub!(:kind, return: 'Reptile')\n+        Dog.kind.should == 'Reptile'\n+        Dog.reset(:kind)\n+        Dog.kind.should == 'Mammal'\n+      end\n+\n+      it \"should restore original instance method\" do\n+        @dog.stub!(:bark, return: 'Meow!')\n+        @dog.bark.should == 'Meow!'\n+        @dog.reset(:bark)\n+        @dog.bark.should == 'Woof!'\n+      end\n+    end\n+\n+    describe \"mocking\" do\n+      it \"should restore original class method\" do\n+        Dog.mock!(:kind, return: 'Reptile')\n+        Dog.kind.should == 'Reptile'\n+        Dog.reset(:kind)\n+        Dog.kind.should == 'Mammal'\n+      end\n+\n+      it \"should restore original instance method\" do","path":"spec/motion-spec/mock_spec.rb","position":180,"original_position":180,"commit_id":"e8d156195be00d54d99d6b0f60fb7d7533b0fd33","original_commit_id":"e8d156195be00d54d99d6b0f60fb7d7533b0fd33","user":{"login":"houndci","id":6697940,"avatar_url":"https://avatars.githubusercontent.com/u/6697940?v=3","gravatar_id":"","url":"https://api.github.com/users/houndci","html_url":"https://github.com/houndci","followers_url":"https://api.github.com/users/houndci/followers","following_url":"https://api.github.com/users/houndci/following{/other_user}","gists_url":"https://api.github.com/users/houndci/gists{/gist_id}","starred_url":"https://api.github.com/users/houndci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/houndci/subscriptions","organizations_url":"https://api.github.com/users/houndci/orgs","repos_url":"https://api.github.com/users/houndci/repos","events_url":"https://api.github.com/users/houndci/events{/privacy}","received_events_url":"https://api.github.com/users/houndci/received_events","type":"User","site_admin":false},"body":"Prefer single-quoted strings when you don't need string interpolation or special symbols.","created_at":"2016-01-07T21:50:14Z","updated_at":"2016-01-07T21:50:14Z","html_url":"https://github.com/jbender/motion-spec/pull/10#discussion_r49130909","pull_request_url":"https://api.github.com/repos/jbender/motion-spec/pulls/10","_links":{"self":{"href":"https://api.github.com/repos/jbender/motion-spec/pulls/comments/49130909"},"html":{"href":"https://github.com/jbender/motion-spec/pull/10#discussion_r49130909"},"pull_request":{"href":"https://api.github.com/repos/jbender/motion-spec/pulls/10"}}},"pull_request":{"url":"https://api.github.com/repos/jbender/motion-spec/pulls/10","id":55390820,"html_url":"https://github.com/jbender/motion-spec/pull/10","diff_url":"https://github.com/jbender/motion-spec/pull/10.diff","patch_url":"https://github.com/jbender/motion-spec/pull/10.patch","issue_url":"https://api.github.com/repos/jbender/motion-spec/issues/10","number":10,"state":"open","locked":false,"title":"Absorb motion-stump","user":{"login":"jbender","id":723784,"avatar_url":"https://avatars.githubusercontent.com/u/723784?v=3","gravatar_id":"","url":"https://api.github.com/users/jbender","html_url":"https://github.com/jbender","followers_url":"https://api.github.com/users/jbender/followers","following_url":"https://api.github.com/users/jbender/following{/other_user}","gists_url":"https://api.github.com/users/jbender/gists{/gist_id}","starred_url":"https://api.github.com/users/jbender/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jbender/subscriptions","organizations_url":"https://api.github.com/users/jbender/orgs","repos_url":"https://api.github.com/users/jbender/repos","events_url":"https://api.github.com/users/jbender/events{/privacy}","received_events_url":"https://api.github.com/users/jbender/received_events","type":"User","site_admin":false},"body":"Mocking/stumping methods to allow for testing in isolation. Not 100% how I want it implemented in the end (would rather just have stubbing and a matcher), but easy enough to get started.\r\n\r\nCurrent:\r\n```ruby\r\ndescribe \"a stubbed string\" do\r\n  let(:string) { \"a string\" }\r\n  before { string.stub!(:length).and_return(500) }\r\n\r\n  it { expect(string.length).to eq(500) }\r\n  it { expect(string.reverse).to eq(\"gnirts a\") } # This will be happy\r\nend\r\n\r\ndescribe \"a mocked string\" do\r\n  let(:string) { \"a string\" }\r\n  before { string.mock!(:length).and_return(500) }\r\n\r\n  it { expect(string.length).to eq(500) }\r\n  it { expect(string.reverse).to eq(\"gnirts a\") } # This will fail\r\nend\r\n```\r\n\r\nGoal:\r\n```ruby\r\ndescribe \"a stubbed string\" do\r\n  let(:string) { \"a string\" }\r\n  before { allow(string).to receive(:length).and_return(500) }\r\n\r\n  it { expect(string.length).to eq(500) }\r\n  it { expect(string.reverse).to eq(\"gnirts a\") }\r\n  it { expect(string).to receive(:length); string.length }\r\nend\r\n```","created_at":"2016-01-07T21:11:08Z","updated_at":"2016-01-07T21:50:15Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6186e40ebe354c15cffa973f6992a8d81e107f45","assignee":{"login":"jbender","id":723784,"avatar_url":"https://avatars.githubusercontent.com/u/723784?v=3","gravatar_id":"","url":"https://api.github.com/users/jbender","html_url":"https://github.com/jbender","followers_url":"https://api.github.com/users/jbender/followers","following_url":"https://api.github.com/users/jbender/following{/other_user}","gists_url":"https://api.github.com/users/jbender/gists{/gist_id}","starred_url":"https://api.github.com/users/jbender/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jbender/subscriptions","organizations_url":"https://api.github.com/users/jbender/orgs","repos_url":"https://api.github.com/users/jbender/repos","events_url":"https://api.github.com/users/jbender/events{/privacy}","received_events_url":"https://api.github.com/users/jbender/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/jbender/motion-spec/pulls/10/commits","review_comments_url":"https://api.github.com/repos/jbender/motion-spec/pulls/10/comments","review_comment_url":"https://api.github.com/repos/jbender/motion-spec/pulls/comments{/number}","comments_url":"https://api.github.com/repos/jbender/motion-spec/issues/10/comments","statuses_url":"https://api.github.com/repos/jbender/motion-spec/statuses/e8d156195be00d54d99d6b0f60fb7d7533b0fd33","head":{"label":"jbender:feature/mocks","ref":"feature/mocks","sha":"e8d156195be00d54d99d6b0f60fb7d7533b0fd33","user":{"login":"jbender","id":723784,"avatar_url":"https://avatars.githubusercontent.com/u/723784?v=3","gravatar_id":"","url":"https://api.github.com/users/jbender","html_url":"https://github.com/jbender","followers_url":"https://api.github.com/users/jbender/followers","following_url":"https://api.github.com/users/jbender/following{/other_user}","gists_url":"https://api.github.com/users/jbender/gists{/gist_id}","starred_url":"https://api.github.com/users/jbender/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jbender/subscriptions","organizations_url":"https://api.github.com/users/jbender/orgs","repos_url":"https://api.github.com/users/jbender/repos","events_url":"https://api.github.com/users/jbender/events{/privacy}","received_events_url":"https://api.github.com/users/jbender/received_events","type":"User","site_admin":false},"repo":{"id":45269421,"name":"motion-spec","full_name":"jbender/motion-spec","owner":{"login":"jbender","id":723784,"avatar_url":"https://avatars.githubusercontent.com/u/723784?v=3","gravatar_id":"","url":"https://api.github.com/users/jbender","html_url":"https://github.com/jbender","followers_url":"https://api.github.com/users/jbender/followers","following_url":"https://api.github.com/users/jbender/following{/other_user}","gists_url":"https://api.github.com/users/jbender/gists{/gist_id}","starred_url":"https://api.github.com/users/jbender/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jbender/subscriptions","organizations_url":"https://api.github.com/users/jbender/orgs","repos_url":"https://api.github.com/users/jbender/repos","events_url":"https://api.github.com/users/jbender/events{/privacy}","received_events_url":"https://api.github.com/users/jbender/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jbender/motion-spec","description":"RubyMotion spec library","fork":false,"url":"https://api.github.com/repos/jbender/motion-spec","forks_url":"https://api.github.com/repos/jbender/motion-spec/forks","keys_url":"https://api.github.com/repos/jbender/motion-spec/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jbender/motion-spec/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jbender/motion-spec/teams","hooks_url":"https://api.github.com/repos/jbender/motion-spec/hooks","issue_events_url":"https://api.github.com/repos/jbender/motion-spec/issues/events{/number}","events_url":"https://api.github.com/repos/jbender/motion-spec/events","assignees_url":"https://api.github.com/repos/jbender/motion-spec/assignees{/user}","branches_url":"https://api.github.com/repos/jbender/motion-spec/branches{/branch}","tags_url":"https://api.github.com/repos/jbender/motion-spec/tags","blobs_url":"https://api.github.com/repos/jbender/motion-spec/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jbender/motion-spec/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jbender/motion-spec/git/refs{/sha}","trees_url":"https://api.github.com/repos/jbender/motion-spec/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jbender/motion-spec/statuses/{sha}","languages_url":"https://api.github.com/repos/jbender/motion-spec/languages","stargazers_url":"https://api.github.com/repos/jbender/motion-spec/stargazers","contributors_url":"https://api.github.com/repos/jbender/motion-spec/contributors","subscribers_url":"https://api.github.com/repos/jbender/motion-spec/subscribers","subscription_url":"https://api.github.com/repos/jbender/motion-spec/subscription","commits_url":"https://api.github.com/repos/jbender/motion-spec/commits{/sha}","git_commits_url":"https://api.github.com/repos/jbender/motion-spec/git/commits{/sha}","comments_url":"https://api.github.com/repos/jbender/motion-spec/comments{/number}","issue_comment_url":"https://api.github.com/repos/jbender/motion-spec/issues/comments{/number}","contents_url":"https://api.github.com/repos/jbender/motion-spec/contents/{+path}","compare_url":"https://api.github.com/repos/jbender/motion-spec/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jbender/motion-spec/merges","archive_url":"https://api.github.com/repos/jbender/motion-spec/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jbender/motion-spec/downloads","issues_url":"https://api.github.com/repos/jbender/motion-spec/issues{/number}","pulls_url":"https://api.github.com/repos/jbender/motion-spec/pulls{/number}","milestones_url":"https://api.github.com/repos/jbender/motion-spec/milestones{/number}","notifications_url":"https://api.github.com/repos/jbender/motion-spec/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jbender/motion-spec/labels{/name}","releases_url":"https://api.github.com/repos/jbender/motion-spec/releases{/id}","created_at":"2015-10-30T18:32:59Z","updated_at":"2015-12-02T01:37:25Z","pushed_at":"2016-01-07T21:50:06Z","git_url":"git://github.com/jbender/motion-spec.git","ssh_url":"git@github.com:jbender/motion-spec.git","clone_url":"https://github.com/jbender/motion-spec.git","svn_url":"https://github.com/jbender/motion-spec","homepage":"","size":123,"stargazers_count":3,"watchers_count":3,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":3,"forks":0,"open_issues":3,"watchers":3,"default_branch":"develop"}},"base":{"label":"jbender:develop","ref":"develop","sha":"7e11bc97b3b8c9fc24895d5e1ac16a7c2446fc93","user":{"login":"jbender","id":723784,"avatar_url":"https://avatars.githubusercontent.com/u/723784?v=3","gravatar_id":"","url":"https://api.github.com/users/jbender","html_url":"https://github.com/jbender","followers_url":"https://api.github.com/users/jbender/followers","following_url":"https://api.github.com/users/jbender/following{/other_user}","gists_url":"https://api.github.com/users/jbender/gists{/gist_id}","starred_url":"https://api.github.com/users/jbender/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jbender/subscriptions","organizations_url":"https://api.github.com/users/jbender/orgs","repos_url":"https://api.github.com/users/jbender/repos","events_url":"https://api.github.com/users/jbender/events{/privacy}","received_events_url":"https://api.github.com/users/jbender/received_events","type":"User","site_admin":false},"repo":{"id":45269421,"name":"motion-spec","full_name":"jbender/motion-spec","owner":{"login":"jbender","id":723784,"avatar_url":"https://avatars.githubusercontent.com/u/723784?v=3","gravatar_id":"","url":"https://api.github.com/users/jbender","html_url":"https://github.com/jbender","followers_url":"https://api.github.com/users/jbender/followers","following_url":"https://api.github.com/users/jbender/following{/other_user}","gists_url":"https://api.github.com/users/jbender/gists{/gist_id}","starred_url":"https://api.github.com/users/jbender/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jbender/subscriptions","organizations_url":"https://api.github.com/users/jbender/orgs","repos_url":"https://api.github.com/users/jbender/repos","events_url":"https://api.github.com/users/jbender/events{/privacy}","received_events_url":"https://api.github.com/users/jbender/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jbender/motion-spec","description":"RubyMotion spec library","fork":false,"url":"https://api.github.com/repos/jbender/motion-spec","forks_url":"https://api.github.com/repos/jbender/motion-spec/forks","keys_url":"https://api.github.com/repos/jbender/motion-spec/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jbender/motion-spec/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jbender/motion-spec/teams","hooks_url":"https://api.github.com/repos/jbender/motion-spec/hooks","issue_events_url":"https://api.github.com/repos/jbender/motion-spec/issues/events{/number}","events_url":"https://api.github.com/repos/jbender/motion-spec/events","assignees_url":"https://api.github.com/repos/jbender/motion-spec/assignees{/user}","branches_url":"https://api.github.com/repos/jbender/motion-spec/branches{/branch}","tags_url":"https://api.github.com/repos/jbender/motion-spec/tags","blobs_url":"https://api.github.com/repos/jbender/motion-spec/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jbender/motion-spec/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jbender/motion-spec/git/refs{/sha}","trees_url":"https://api.github.com/repos/jbender/motion-spec/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jbender/motion-spec/statuses/{sha}","languages_url":"https://api.github.com/repos/jbender/motion-spec/languages","stargazers_url":"https://api.github.com/repos/jbender/motion-spec/stargazers","contributors_url":"https://api.github.com/repos/jbender/motion-spec/contributors","subscribers_url":"https://api.github.com/repos/jbender/motion-spec/subscribers","subscription_url":"https://api.github.com/repos/jbender/motion-spec/subscription","commits_url":"https://api.github.com/repos/jbender/motion-spec/commits{/sha}","git_commits_url":"https://api.github.com/repos/jbender/motion-spec/git/commits{/sha}","comments_url":"https://api.github.com/repos/jbender/motion-spec/comments{/number}","issue_comment_url":"https://api.github.com/repos/jbender/motion-spec/issues/comments{/number}","contents_url":"https://api.github.com/repos/jbender/motion-spec/contents/{+path}","compare_url":"https://api.github.com/repos/jbender/motion-spec/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jbender/motion-spec/merges","archive_url":"https://api.github.com/repos/jbender/motion-spec/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jbender/motion-spec/downloads","issues_url":"https://api.github.com/repos/jbender/motion-spec/issues{/number}","pulls_url":"https://api.github.com/repos/jbender/motion-spec/pulls{/number}","milestones_url":"https://api.github.com/repos/jbender/motion-spec/milestones{/number}","notifications_url":"https://api.github.com/repos/jbender/motion-spec/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jbender/motion-spec/labels{/name}","releases_url":"https://api.github.com/repos/jbender/motion-spec/releases{/id}","created_at":"2015-10-30T18:32:59Z","updated_at":"2015-12-02T01:37:25Z","pushed_at":"2016-01-07T21:50:06Z","git_url":"git://github.com/jbender/motion-spec.git","ssh_url":"git@github.com:jbender/motion-spec.git","clone_url":"https://github.com/jbender/motion-spec.git","svn_url":"https://github.com/jbender/motion-spec","homepage":"","size":123,"stargazers_count":3,"watchers_count":3,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":3,"forks":0,"open_issues":3,"watchers":3,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/jbender/motion-spec/pulls/10"},"html":{"href":"https://github.com/jbender/motion-spec/pull/10"},"issue":{"href":"https://api.github.com/repos/jbender/motion-spec/issues/10"},"comments":{"href":"https://api.github.com/repos/jbender/motion-spec/issues/10/comments"},"review_comments":{"href":"https://api.github.com/repos/jbender/motion-spec/pulls/10/comments"},"review_comment":{"href":"https://api.github.com/repos/jbender/motion-spec/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/jbender/motion-spec/pulls/10/commits"},"statuses":{"href":"https://api.github.com/repos/jbender/motion-spec/statuses/e8d156195be00d54d99d6b0f60fb7d7533b0fd33"}}}}