1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
Feature: block local expectations
Background:
Given a file named "lib/account.rb" with:
"""
class Account
def self.create
yield new
end
def opening_balance(amount, currency)
end
end
"""
Scenario: passing example
Given a file named "spec/account_spec.rb" with:
"""
require 'account'
describe "account DSL" do
it "it succeeds when the block local receives the given call" do
account = double("Account")
Account.should_receive(:create).and_yield(account) do |account|
account.should_receive(:opening_balance).with(100, :USD)
end
Account.create do |account|
account.opening_balance 100, :USD
end
end
end
"""
When I run `rspec spec/account_spec.rb`
Then the output should contain "1 example, 0 failures"
Scenario: failing example
Given a file named "spec/account_spec.rb" with:
"""
require 'account'
describe "account DSL" do
it "fails when the block local does not receive the expected call" do
Account.should_receive(:create).and_yield do |account|
account.should_receive(:opening_balance).with(100, :USD)
end
Account.create do |account|
# opening_balance is not called here
end
end
end
"""
When I run `rspec spec/account_spec.rb`
Then the output should contain "1 example, 1 failure"
|