features/fakes/anonymous_doubles.feature in bogus-0.0.4 vs features/fakes/anonymous_doubles.feature in bogus-0.1.0
- old
+ new
@@ -1,18 +1,18 @@
Feature: Anonymous test doubles
Anonymous test doubles can be useful as a stepping stone towards actual fakes and when migrating from another testing library.
- In contrast with other testing libraries, Bogus makes its fakes respond to all methods by default and makes those calls chainable. This way you can spy on methods without stubbing them first.
+ In contrast with other testing libraries, Bogus makes its fakes respond to all methods by default. This way you can spy on methods without stubbing them first.
- It is not advisable to use those for anything else than an intermediate step. Fakes that mimic an actual class have many more benefits.
+ It is not advisable to use those for anything else than an intermediate step. Fakes that mimic an actual class have many more benefits.
The syntax for defining fakes is:
fake(method_1: return_value, method_2: proc{return_value2})
- If you pass a proc as a return value to a fake, the proc will be called to obtain the value. This can be used for instance to raise errors in stubbed methods.
+ If you pass a proc as a return value to a fake, the proc will be called to obtain the value. This can be used for instance to raise errors in stubbed methods.
If you want to actually return a proc from a method, you need to use a slightly longer syntax:
factory = fake()
stub(factory).make_validator{ proc{ false } }
@@ -79,11 +79,11 @@
"""ruby
describe Student do
let(:library) { fake }
let(:jake) { Student.new("Jake") }
- it "allows stubbing any method with any parameters" do
+ it "allows mocking any method with any parameters" do
mock(library).register_junior("Jake") { "the card" }
jake.sign_up(library)
jake.library_card.should == "the card"
@@ -122,11 +122,11 @@
"""ruby
describe Student do
let(:library) { fake }
let(:jake) { Student.new("Jake") }
- it "allows stubbing any method with any parameters" do
+ it "allows spying on any method" do
jake.sign_up(library)
library.should have_received.register_junior("Jake")
end
end
@@ -136,10 +136,14 @@
Then spec file with following content should pass:
"""ruby
describe Student do
let(:library) { fake }
- it "allows stubbing any method with any parameters" do
- library.foo.bar("hello").baz.should == library
+ it "allows calling any method with any parameters" do
+ expect {
+ library.foo
+ library.bar("hello")
+ library.baz(1, 2, 3, 4, 5)
+ }.not_to raise_error
end
end
"""