{"action":"opened","issue":{"url":"https://api.github.com/repos/ave-hikari/magekeep/issues/8","repository_url":"https://api.github.com/repos/ave-hikari/magekeep","labels_url":"https://api.github.com/repos/ave-hikari/magekeep/issues/8/labels{/name}","comments_url":"https://api.github.com/repos/ave-hikari/magekeep/issues/8/comments","events_url":"https://api.github.com/repos/ave-hikari/magekeep/issues/8/events","html_url":"https://github.com/ave-hikari/magekeep/issues/8","id":345120167,"node_id":"MDU6SXNzdWUzNDUxMjAxNjc=","number":8,"title":"Rspec書き方","user":{"login":"ave-hikari","id":11960818,"node_id":"MDQ6VXNlcjExOTYwODE4","avatar_url":"https://avatars0.githubusercontent.com/u/11960818?v=4","gravatar_id":"","url":"https://api.github.com/users/ave-hikari","html_url":"https://github.com/ave-hikari","followers_url":"https://api.github.com/users/ave-hikari/followers","following_url":"https://api.github.com/users/ave-hikari/following{/other_user}","gists_url":"https://api.github.com/users/ave-hikari/gists{/gist_id}","starred_url":"https://api.github.com/users/ave-hikari/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ave-hikari/subscriptions","organizations_url":"https://api.github.com/users/ave-hikari/orgs","repos_url":"https://api.github.com/users/ave-hikari/repos","events_url":"https://api.github.com/users/ave-hikari/events{/privacy}","received_events_url":"https://api.github.com/users/ave-hikari/received_events","type":"User","site_admin":false},"labels":[{"id":962678276,"node_id":"MDU6TGFiZWw5NjI2NzgyNzY=","url":"https://api.github.com/repos/ave-hikari/magekeep/labels/%E8%AA%AD%E3%81%BF%E8%BF%94%E3%81%99","name":"読み返す","color":"a2eeef","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-07-27T07:29:30Z","updated_at":"2018-07-27T07:29:30Z","closed_at":null,"author_association":"OWNER","body":"#### modelのspecを書いて、view では stub させてテストする\r\n- spec/model/\r\n```ruby\r\n  # ex)  /model/picture.rb とする\r\n\r\n  let(:picture) { described_class.new(valid_params) }\r\n\r\n  # bool を返却する is_XXXX? のテスト\r\n  describe '#is_XXXX?' do\r\n    context 'A' do\r\n      it do\r\n        expect(picture.is_XXXX?).to be_falsy\r\n      end\r\n    end\r\n\r\n    context 'B' do\r\n      let!(:picture) { create(:picture, deleted_at: Time.current) }\r\n\r\n      it do\r\n        expect(picture.is_XXXX?).to be_truthy\r\n      end\r\n    end\r\n  end\r\n```\r\n\r\n- spec/system/\r\n**allow to receive**\r\n```ruby\r\n        context 'AAA' do\r\n          let!(:picture) { create(:picture, deleted_at: Time.current) }\r\n\r\n          before do\r\n            allow(picture).to receive(:is_XXXX?).and_return(true)\r\n          end\r\n\r\n          it do\r\n            visit picture_path\r\n            expect(page).to have_content 'あたり'\r\n          end\r\n        end\r\n```\r\n**allow_any_instance_of**\r\n```ruby\r\n        context 'BBB' do\r\n          before do\r\n            allow_any_instance_of(Picture).to receive(:is_XXXX?).and_return(false) # こっちはインスタンスを受けて実行\r\n          end\r\n\r\n          it do\r\n            visit picture_path\r\n            expect(page).to have_content 'はずれ'\r\n          end\r\n        end\r\n```"}}
{"actor":{"display_login":"ave-hikari"}}