Sha256: cb71f7669fbf602fd1bbba4db65e7fd9a89c268dc392bb66b18b7af0c8d171f2

Contents?: true

Size: 1.37 KB

Versions: 120

Compression:

Stored size: 1.37 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(:ignore) {}
    ignore.question?.should eq(:answer)
  end

  it "raises when method is missing from local scope as well as matcher" do
    RSpec::Matchers::define(:ignore) {}
    expect { ignore.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(:ignore) {}
      ignore.should respond_to(:question?)
    end

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

Version data entries

120 entries across 69 versions & 11 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/rspec-expectations-2.9.1/spec/rspec/matchers/dsl_spec.rb
classiccms-0.7.5 vendor/bundle/gems/rspec-expectations-2.10.0/spec/rspec/matchers/dsl_spec.rb
classiccms-0.7.4 vendor/bundle/gems/rspec-expectations-2.10.0/spec/rspec/matchers/dsl_spec.rb
classiccms-0.7.4 vendor/bundle/gems/rspec-expectations-2.9.1/spec/rspec/matchers/dsl_spec.rb
classiccms-0.7.3 vendor/bundle/gems/rspec-expectations-2.10.0/spec/rspec/matchers/dsl_spec.rb
classiccms-0.7.3 vendor/bundle/gems/rspec-expectations-2.9.1/spec/rspec/matchers/dsl_spec.rb
tnargav-1.3.3 vendor/bundle/ruby/1.9.1/gems/rspec-expectations-2.11.3/spec/rspec/matchers/dsl_spec.rb
tnargav-1.2.3 vendor/bundle/ruby/1.9.1/gems/rspec-expectations-2.11.3/spec/rspec/matchers/dsl_spec.rb
classiccms-0.7.2 vendor/bundle/gems/rspec-expectations-2.10.0/spec/rspec/matchers/dsl_spec.rb
classiccms-0.7.2 vendor/bundle/gems/rspec-expectations-2.9.1/spec/rspec/matchers/dsl_spec.rb
classiccms-0.7.1 vendor/bundle/gems/rspec-expectations-2.10.0/spec/rspec/matchers/dsl_spec.rb
classiccms-0.7.1 vendor/bundle/gems/rspec-expectations-2.9.1/spec/rspec/matchers/dsl_spec.rb
classiccms-0.7.0 vendor/bundle/gems/rspec-expectations-2.9.1/spec/rspec/matchers/dsl_spec.rb
classiccms-0.7.0 vendor/bundle/gems/rspec-expectations-2.10.0/spec/rspec/matchers/dsl_spec.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/rspec-expectations-2.10.0/spec/rspec/matchers/dsl_spec.rb
classiccms-0.6.9 vendor/bundle/gems/rspec-expectations-2.10.0/spec/rspec/matchers/dsl_spec.rb
classiccms-0.6.9 vendor/bundle/gems/rspec-expectations-2.9.1/spec/rspec/matchers/dsl_spec.rb
classiccms-0.6.8 vendor/bundle/gems/rspec-expectations-2.9.1/spec/rspec/matchers/dsl_spec.rb
classiccms-0.6.8 vendor/bundle/gems/rspec-expectations-2.10.0/spec/rspec/matchers/dsl_spec.rb
classiccms-0.6.7 vendor/bundle/gems/rspec-expectations-2.10.0/spec/rspec/matchers/dsl_spec.rb