Sha256: 50456e03a0d3db639d56cbb55ce8f7bfa92036b758a8498c22ba425316486bd5

Contents?: true

Size: 1.77 KB

Versions: 4

Compression:

Stored size: 1.77 KB

Contents

Feature: block local expectations

  In order to set message expectations on ...
  As an RSpec user
  I want to configure the evaluation context

  Background:
    Given a file named "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 "account_passing_spec.rb" with:
      """
      require 'account'

      Rspec::Core.configure do |config|
        config.mock_framework = :rspec
      end

      describe "account DSL" do
        it "it succeeds when the block local receives the given call" do
          account = Account.new
          Account.should_receive(:create).and_yield do |account|
            account.should_receive(:opening_balance).with(100, :USD)
          end
          Account.create do
            opening_balance 100, :USD
          end
        end
      end
      """
    When I run "rspec account_passing_spec.rb"
    Then the stdout should match "1 example, 0 failures"
    
  Scenario: failing example
    
    Given a file named "account_failing_spec.rb" with:
      """
      require 'account'

      Rspec::Core.configure do |config|
        config.mock_framework = :rspec
      end

      describe "account DSL" do
        it "fails when the block local does not receive the expected call" do
          account = Account.new
          Account.should_receive(:create).and_yield do |account|
            account.should_receive(:opening_balance).with(100, :USD)
          end
          Account.create do
            # opening_balance is not called here
          end
        end
      end
      """

    When I run "rspec account_failing_spec.rb"
    Then the stdout should match "1 example, 1 failure"

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rspec-core-2.0.0.a5 features/mocks/block_local_expectations.feature
rspec-core-2.0.0.a4 features/mocks/block_local_expectations.feature
rspec-core-2.0.0.a3 features/mocks/block_local_expectations.feature
rspec-core-2.0.0.a2 features/mocks/block_local_expectations.feature