Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

この間のアレにspec追加しました。 #12

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions spec/great_class_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
describe GreatClass do
describe 'some_subject_method' do
subject { described_class.new }
before do
allow(SomeModule).to receive(:some_important_method).and_return 'stubbed_value'
subject.some_subject_method
end
it 'makes itself special!' do
is_expected.to be_some_special_state
end
it 'remembers to do the important thing!' do
expect(SomeModule).to receive(:some_important_method)
subject.some_subject_method
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ ああ、ここDRYじゃない。
beforeブロックのsubject.some_subject_methodと完全にダブってます。
これだけ単純なメソッド呼び出しだから気にならないかもしれませんが、
引数が多かったり、もっと複雑な場合でもこのように書きますか?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

それに、やっぱり他のexampleと違って、
expectationを先に書くのが
なんだかあまりしっくりきませんねぇ。 😕

「対象のメソッドを呼んだ後に〇〇な影響を起こす」
という観点で書くほうが自然じゃありませんか?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

まぁ、要するに、私が作ったcrispyを使って #13 のように書き換えてください。

end
end
end