Sha256: ef03af6ace23df62097511b9e27cb3e2afd256e9d50555b968d7c0c69a9e300e

Contents?: true

Size: 1.42 KB

Versions: 43

Compression:

Stored size: 1.42 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| expect(actual).to be_ok }
    end

    expect(ok).to be_well
  end

  it "has access to methods available in the scope of the example" do
    RSpec::Matchers::define(:matcher_a) {}
    expect(matcher_a.question?).to 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

    expect(3).to be_just_like(3)
    expect(4).to be_just_like(4)
  end

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

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

Version data entries

43 entries across 43 versions & 12 rubygems

Version Path
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.4.0/gems/rspec-expectations-2.14.5/spec/rspec/matchers/dsl_spec.rb
vagrant-unbundled-1.9.5.1 vendor/bundle/ruby/2.4.0/gems/rspec-expectations-2.14.5/spec/rspec/matchers/dsl_spec.rb
vagrant-unbundled-1.9.1.1 vendor/bundle/ruby/2.4.0/gems/rspec-expectations-2.14.5/spec/rspec/matchers/dsl_spec.rb
vagrant-unbundled-1.8.5.2 vendor/bundle/ruby/2.3.0/gems/rspec-expectations-2.14.5/spec/rspec/matchers/dsl_spec.rb
vagrant-unbundled-1.8.5.1 vendor/bundle/ruby/2.3.0/gems/rspec-expectations-2.14.5/spec/rspec/matchers/dsl_spec.rb
vagrant-unbundled-1.8.4.2 vendor/bundle/ruby/2.3.0/gems/rspec-expectations-2.14.5/spec/rspec/matchers/dsl_spec.rb
vagrant-unbundled-1.8.4.1 vendor/bundle/ruby/2.3.0/gems/rspec-expectations-2.14.5/spec/rspec/matchers/dsl_spec.rb
vagrant-unbundled-1.8.1.1 vendor/bundle/ruby/2.3.0/gems/rspec-expectations-2.14.5/spec/rspec/matchers/dsl_spec.rb
vagrant-cloudstack-1.1.0 vendor/bundle/gems/rspec-expectations-2.14.5/spec/rspec/matchers/dsl_spec.rb
judge-2.0.5 vendor/bundle/ruby/2.1.0/gems/rspec-expectations-2.13.0/spec/rspec/matchers/dsl_spec.rb
rspec-expectations-2.99.2 spec/rspec/matchers/dsl_spec.rb
dxruby_rp5-0.0.4 spec/vendor/rspec-expectations-2.14.4/spec/rspec/matchers/dsl_spec.rb
rspec-expectations-2.99.1 spec/rspec/matchers/dsl_spec.rb
rspec-expectations-2.99.0 spec/rspec/matchers/dsl_spec.rb
rspec-expectations-2.99.0.rc1 spec/rspec/matchers/dsl_spec.rb
rspec-expectations-2.99.0.beta2 spec/rspec/matchers/dsl_spec.rb
rspec-expectations-2.14.5 spec/rspec/matchers/dsl_spec.rb
mango-0.8.0 vendor/bundler/ruby/2.1.0/gems/rspec-expectations-2.14.4/spec/rspec/matchers/dsl_spec.rb
mango-0.7.1 vendor/bundler/ruby/2.0.0/gems/rspec-expectations-2.14.4/spec/rspec/matchers/dsl_spec.rb
dxruby_rp5-0.0.3 spec/vendor/rspec-expectations-2.14.4/spec/rspec/matchers/dsl_spec.rb