Sha256: db75b03075a82197da2c94cecca78e8d20700d21834a3051ab7e12b256f9b7e4

Contents?: true

Size: 1.39 KB

Versions: 6

Compression:

Stored size: 1.39 KB

Contents

require 'spec_helper'

describe "a matcher defined using the matcher DSL" do
  def question?
    :answer
  end

  def ok
    "ok"
  end

  it "supports calling custom matchers from within other custom matchers" do
    RSpec::Matchers.define :be_ok do
      match { |actual| actual == ok }
    end

    RSpec::Matchers.define :be_well do
      match { |actual| actual.should be_ok }
    end

    ok.should be_well
  end

  it "has access to methods available in the scope of the example" do
    RSpec::Matchers::define(:matcher_a) {}
    matcher_a.question?.should eq(:answer)
  end

  it "raises when method is missing from local scope as well as matcher" do
    RSpec::Matchers::define(:matcher_b) {}
    expect { matcher_b.i_dont_exist }.to raise_error(NameError)
  end

  it "clears user instance variables between invocations" do
    RSpec::Matchers::define(:be_just_like) do |expected|
      match do |actual|
        @foo ||= expected
        @foo == actual
      end
    end

    3.should be_just_like(3)
    4.should be_just_like(4)
  end

  describe "#respond_to?" do
    it "returns true for methods in example scope" do
      RSpec::Matchers::define(:matcher_c) {}
      matcher_c.should respond_to(:question?)
    end

    it "returns false for methods not defined in matcher or example scope" do
      RSpec::Matchers::define(:matcher_d) {}
      matcher_d.should_not respond_to(:i_dont_exist)
    end
  end
end

Version data entries

6 entries across 6 versions & 3 rubygems

Version Path
librarian-puppet-0.9.9 vendor/gems/ruby/1.9.1/gems/rspec-expectations-2.12.1/spec/rspec/matchers/dsl_spec.rb
remq-0.0.4 vendor/bundle/gems/rspec-expectations-2.12.1/spec/rspec/matchers/dsl_spec.rb
remq-0.0.3 vendor/bundle/gems/rspec-expectations-2.12.1/spec/rspec/matchers/dsl_spec.rb
librarian-puppet-0.9.8 vendor/gems/ruby/1.9.1/gems/rspec-expectations-2.12.1/spec/rspec/matchers/dsl_spec.rb
rspec-expectations-2.12.1 spec/rspec/matchers/dsl_spec.rb
rspec-expectations-2.12.0 spec/rspec/matchers/dsl_spec.rb