in Gemfile:
group :test do
gem 'rspec-rails', '3.1.0'
gem 'rspec-activemodel-mocks'
gem 'factory_girl_rails'
gem 'ffaker'
gem 'capybara'
#gem "capybara-webkit"
gem 'selenium-webdriver'
end
obj.stub(:message) do |arg1, arg2|
# set expectations about the args in this block
# and set a return value
end
describe "a stubbed implementation" do
it "works" do
object = Object.new
object.stub(:foo) do |arg|
if arg == :this
"got this"
elsif arg == :that
"got that"
end
end
object.foo(:this).should eq("got this")
object.foo(:that).should eq("got that")
end
end
RSpec.describe "Verifying arguments using a block" do
it "fails when the arguments do not meet the expectations set in the block" do
dbl = double
allow(dbl).to receive(:foo) do |arg|
expect(arg).to eq("bar")
end
dbl.foo(nil)
end
end
- for any_instance_of
allow_any_instance_of(MyClass).to receive(:run) do |obj, arg1|
expect(arg1).to match /bar /
end