spec/bogus/mocking_dsl_spec.rb in bogus-0.1.4 vs spec/bogus/mocking_dsl_spec.rb in bogus-0.1.5
- old
+ new
@@ -28,29 +28,29 @@
let(:baz) { ExampleFoo.new }
it "allows stubbing the existing methods" do
Stubber.stub(baz).foo("bar") { :return_value }
- baz.foo("bar").should == :return_value
+ expect(baz.foo("bar")).to eq :return_value
end
it "can stub method with any parameters" do
Stubber.stub(baz).foo(Stubber.any_args) { :default_value }
Stubber.stub(baz).foo("bar") { :foo_value }
- baz.foo("a").should == :default_value
- baz.foo("b").should == :default_value
- baz.foo("bar").should == :foo_value
+ expect(baz.foo("a")).to eq :default_value
+ expect(baz.foo("b")).to eq :default_value
+ expect(baz.foo("bar")).to eq :foo_value
end
it "can stub method with some wildcard parameters" do
Stubber.stub(baz).hello(Stubber.any_args) { :default_value }
Stubber.stub(baz).hello("welcome", Stubber.anything) { :greeting_value }
- baz.hello("hello", "adam").should == :default_value
- baz.hello("welcome", "adam").should == :greeting_value
- baz.hello("welcome", "rudy").should == :greeting_value
+ expect(baz.hello("hello", "adam")).to eq :default_value
+ expect(baz.hello("welcome", "adam")).to eq :greeting_value
+ expect(baz.hello("welcome", "rudy")).to eq :greeting_value
end
it "does not allow stubbing non-existent methods" do
baz = ExampleFoo.new
expect do
@@ -61,59 +61,59 @@
it "unstubs methods after each test" do
Stubber.stub(ExampleFoo).bar("John") { "something else" }
Bogus.after_each_test
- ExampleFoo.bar("John").should == "Hello John"
+ expect(ExampleFoo.bar("John")).to eq "Hello John"
end
end
describe "#have_received" do
context "with a fake object" do
let(:the_fake) { Bogus.fake_for(:example_foo) }
it "allows verifying that fakes have correct interfaces" do
the_fake.foo("test")
- the_fake.should Stubber.have_received.foo("test")
+ expect(the_fake).to Stubber.have_received.foo("test")
end
it "does not allow verifying on non-existent methods" do
expect {
- the_fake.should Stubber.have_received.bar("test")
+ expect(the_fake).to Stubber.have_received.bar("test")
}.to raise_error(NameError)
end
it "does not allow verifying on methods with a wrong argument count" do
expect {
- the_fake.should Stubber.have_received.foo("test", "test 2")
+ expect(the_fake).to Stubber.have_received.foo("test", "test 2")
}.to raise_error(ArgumentError)
end
it "allows spying on methods with optional parameters" do
the_fake.with_optional_args(123)
- the_fake.should Stubber.have_received.with_optional_args(123)
+ expect(the_fake).to Stubber.have_received.with_optional_args(123)
end
end
it "can be used with plain old Ruby objects" do
object = ExampleFoo.new
Stubber.stub(object).foo(Stubber.any_args)
object.foo('test')
- object.should Stubber.have_received.foo("test")
+ expect(object).to Stubber.have_received.foo("test")
end
it "allows spying on methods with optional parameters" do
object = ExampleFoo.new
Stubber.stub(object).with_optional_args(123) { 999 }
- object.with_optional_args(123).should == 999
+ expect(object.with_optional_args(123)).to eq 999
- object.should Stubber.have_received.with_optional_args(123)
+ expect(object).to Stubber.have_received.with_optional_args(123)
end
class ClassWithMatches
def matches?(something)
end
@@ -122,11 +122,11 @@
it "can be used with objects that have same methods as an RSpec expectation" do
fake = Bogus.fake_for(:class_with_matches)
fake.matches?("foo")
- fake.should Bogus.have_received.matches?("foo")
+ expect(fake).to Bogus.have_received.matches?("foo")
end
class PassesSelfToCollaborator
def hello(example)
example.foo(self)
@@ -139,11 +139,11 @@
fake = Bogus.fake_for(:example_foo)
object = PassesSelfToCollaborator.new
object.hello(fake)
- fake.should Bogus.have_received.foo(object)
+ expect(fake).to Bogus.have_received.foo(object)
end
end
class Mocker
extend Bogus::MockingDSL
@@ -155,27 +155,27 @@
shared_examples_for "mocking dsl" do
it "allows mocking on methods with optional parameters" do
Mocker.mock(baz).with_optional_args(1) { :return }
- baz.with_optional_args(1).should == :return
+ expect(baz.with_optional_args(1)).to eq :return
expect { Bogus.after_each_test }.not_to raise_error
end
it "allows mocking with anything" do
Mocker.mock(baz).hello(1, Bogus::Anything) { :return }
- baz.hello(1, 2).should == :return
+ expect(baz.hello(1, 2)).to eq :return
expect { Bogus.after_each_test }.not_to raise_error
end
it "allows mocking the existing methods" do
Mocker.mock(baz).foo("bar") { :return_value }
- baz.foo("bar").should == :return_value
+ expect(baz.foo("bar")).to eq :return_value
expect { Bogus.after_each_test }.not_to raise_error
end
it "verifies that the methods mocked exist" do
@@ -244,34 +244,34 @@
it "creates objects that can be stubbed" do
greeter = fake
stub(greeter).greet("Jake") { "Hello Jake" }
- greeter.greet("Jake").should == "Hello Jake"
+ expect(greeter.greet("Jake")).to eq "Hello Jake"
end
it "creates objects that can be mocked" do
greeter = fake
mock(greeter).greet("Jake") { "Hello Jake" }
- greeter.greet("Jake").should == "Hello Jake"
+ expect(greeter.greet("Jake")).to eq "Hello Jake"
end
it "creates objects with some methods stubbed by default" do
greeter = fake(greet: "Hello Jake")
- greeter.greet("Jake").should == "Hello Jake"
+ expect(greeter.greet("Jake")).to eq "Hello Jake"
end
it "creates objects that can be spied upon" do
greeter = fake
greeter.greet("Jake")
- greeter.should have_received.greet("Jake")
- greeter.should_not have_received.greet("Bob")
+ expect(greeter).to have_received.greet("Jake")
+ expect(greeter).to_not have_received.greet("Bob")
end
it "verifies mock expectations set on anonymous fakes" do
greeter = fake
mock(greeter).greet("Jake") { "Hello Jake" }
@@ -305,19 +305,19 @@
end
it "returns configured fakes" do
the_fake = Stubber.fake(:globally_configured_fake)
- the_fake.foo('a').should == "foo"
- the_fake.bar('a', 'b').should == "bar"
+ expect(the_fake.foo('a')).to eq "foo"
+ expect(the_fake.bar('a', 'b')).to eq "bar"
end
it "allows overwriting stubbed methods" do
the_fake = Stubber.fake(:globally_configured_fake, bar: "baz")
- the_fake.foo('a').should == "foo"
- the_fake.bar('a', 'b').should == "baz"
+ expect(the_fake.foo('a')).to eq "foo"
+ expect(the_fake.bar('a', 'b')).to eq "baz"
end
it "evaluates the block passed to method in configuration when method is called" do
the_fake = Stubber.fake(:globally_configured_fake)
@@ -338,28 +338,28 @@
end
it "replaces the class for the duration of the test" do
Stubber.fake_class(ThisClassWillBeReplaced, hello: "replaced!")
- ThisClassWillBeReplaced.hello("foo").should == "replaced!"
- ThisClassWillBeReplaced.should_not equal(TheOriginalClass)
+ expect(ThisClassWillBeReplaced.hello("foo")).to eq "replaced!"
+ expect(ThisClassWillBeReplaced).to_not equal(TheOriginalClass)
end
it "makes it possible to spy on classes" do
Stubber.fake_class(ThisClassWillBeReplaced)
ThisClassWillBeReplaced.hello("foo")
- ThisClassWillBeReplaced.should Bogus.have_received.hello("foo")
- ThisClassWillBeReplaced.should_not Bogus.have_received.hello("bar")
+ expect(ThisClassWillBeReplaced).to Bogus.have_received.hello("foo")
+ expect(ThisClassWillBeReplaced).to_not Bogus.have_received.hello("bar")
end
it "restores the class after the test has finished" do
Stubber.fake_class(ThisClassWillBeReplaced)
Bogus.reset_overwritten_classes
- ThisClassWillBeReplaced.should equal(TheOriginalClass)
+ expect(ThisClassWillBeReplaced).to equal(TheOriginalClass)
end
end
class SampleForContracts
def initialize(name)
@@ -383,20 +383,20 @@
Bogus.record_calls_for(:sample_for_contracts, SampleForContracts)
end
it "passes when all the mocked interactions were executed" do
- sample.greet("Welcome").should == "Welcome, John!"
+ expect(sample.greet("Welcome")).to eq "Welcome, John!"
Bogus.after_each_test
expect {
Bogus.verify_contract!(:sample_for_contracts)
}.not_to raise_error
end
it "fails when contracts are fullfilled" do
- sample.greet("Hello").should == "Hello, John!"
+ expect(sample.greet("Hello")).to eq "Hello, John!"
Bogus.after_each_test
expect {
Bogus.verify_contract!(:sample_for_contracts)