Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Very basic specs for stub + mocks support
- Loading branch information
1 parent
e309d0d
commit 1b38065
Showing
3 changed files
with
57 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
describe "RSpec mocks" do | ||
describe "stubs" do | ||
it "can stub basic methods" do | ||
obj = Object.new | ||
expect(obj).to receive(:foo) { 100 } | ||
obj.foo.should == 100 | ||
end | ||
|
||
it "raises an exception when stub returns wrong value" do | ||
expect { | ||
obj = Object.new | ||
expect(obj).to receive(:bar) { 400 } | ||
obj.bar.should == 42 | ||
}.to raise_error(Exception) | ||
end | ||
end | ||
|
||
describe "doubles" do | ||
it "define methods on double" do | ||
person = double("person", :name => "Adam") | ||
expect(person.name).to eq("Adam") | ||
end | ||
|
||
it "once" do | ||
person = double("person") | ||
expect(person).to receive(:name).once | ||
person.name.should eq(nil) | ||
end | ||
|
||
it "twice" do | ||
person = double("person") | ||
expect(person).to receive(:name).twice | ||
person.name | ||
person.name | ||
end | ||
end | ||
end |