spec/rspec/matchers/matcher_spec.rb in rspec-expectations-2.0.0.beta.8 vs spec/rspec/matchers/matcher_spec.rb in rspec-expectations-2.0.0.beta.9

- old
+ new

@@ -1,15 +1,15 @@ require 'spec_helper' class UnexpectedError < StandardError; end -module Rspec +module RSpec module Matchers describe Matcher do context "without overrides" do before(:each) do - @matcher = Rspec::Matchers::Matcher.new(:be_a_multiple_of, 3) do |multiple| + @matcher = RSpec::Matchers::Matcher.new(:be_a_multiple_of, 3) do |multiple| match do |actual| actual % multiple == 0 end end end @@ -28,57 +28,57 @@ @matcher.failure_message_for_should_not.should == "expected 9 not to be a multiple of 3" end end it "is not diffable by default" do - matcher = Rspec::Matchers::Matcher.new(:name) {} + matcher = RSpec::Matchers::Matcher.new(:name) {} matcher.should_not be_diffable end it "is diffable when told to be" do - matcher = Rspec::Matchers::Matcher.new(:name) { diffable } + matcher = RSpec::Matchers::Matcher.new(:name) { diffable } matcher.should be_diffable end it "provides expected" do - matcher = Rspec::Matchers::Matcher.new(:name, 'expected string') {} + matcher = RSpec::Matchers::Matcher.new(:name, 'expected string') {} matcher.expected.should == ['expected string'] end it "provides actual" do - matcher = Rspec::Matchers::Matcher.new(:name, 'expected string') do + matcher = RSpec::Matchers::Matcher.new(:name, 'expected string') do match {|actual|} end matcher.matches?('actual string') matcher.actual.should == 'actual string' end context "wrapping another expectation (should == ...)" do it "returns true if the wrapped expectation passes" do - matcher = Rspec::Matchers::Matcher.new(:name, 'value') do |expected| + matcher = RSpec::Matchers::Matcher.new(:name, 'value') do |expected| match do |actual| actual.should == expected end end matcher.matches?('value').should be_true end it "returns false if the wrapped expectation fails" do - matcher = Rspec::Matchers::Matcher.new(:name, 'value') do |expected| + matcher = RSpec::Matchers::Matcher.new(:name, 'value') do |expected| match do |actual| actual.should == expected end end matcher.matches?('other value').should be_false end end context "with overrides" do before(:each) do - @matcher = Rspec::Matchers::Matcher.new(:be_boolean, true) do |boolean| + @matcher = RSpec::Matchers::Matcher.new(:be_boolean, true) do |boolean| match do |actual| actual end description do "be the boolean #{boolean}" @@ -115,31 +115,31 @@ end end context "#new" do it "passes matches? arg to match block" do - matcher = Rspec::Matchers::Matcher.new(:ignore) do + matcher = RSpec::Matchers::Matcher.new(:ignore) do match do |actual| actual == 5 end end matcher.matches?(5).should be_true end it "exposes arg submitted through #new to matcher block" do - matcher = Rspec::Matchers::Matcher.new(:ignore, 4) do |expected| + matcher = RSpec::Matchers::Matcher.new(:ignore, 4) do |expected| match do |actual| actual > expected end end matcher.matches?(5).should be_true end end context "with no args" do before(:each) do - @matcher = Rspec::Matchers::Matcher.new(:matcher_name) do + @matcher = RSpec::Matchers::Matcher.new(:matcher_name) do match do |actual| actual == 5 end end end @@ -153,11 +153,11 @@ end end context "with 1 arg" do before(:each) do - @matcher = Rspec::Matchers::Matcher.new(:matcher_name, 1) do |expected| + @matcher = RSpec::Matchers::Matcher.new(:matcher_name, 1) do |expected| match do |actual| actual == 5 && expected == 1 end end end @@ -171,11 +171,11 @@ end end context "with multiple args" do before(:each) do - @matcher = Rspec::Matchers::Matcher.new(:matcher_name, 1, 2, 3, 4) do |a,b,c,d| + @matcher = RSpec::Matchers::Matcher.new(:matcher_name, 1, 2, 3, 4) do |a,b,c,d| match do |sum| a + b + c + d == sum end end end @@ -188,11 +188,11 @@ @matcher.description.should == "matcher name 1, 2, 3, and 4" end end it "supports helper methods" do - matcher = Rspec::Matchers::Matcher.new(:be_similar_to, [1,2,3]) do |sample| + matcher = RSpec::Matchers::Matcher.new(:be_similar_to, [1,2,3]) do |sample| match do |actual| similar?(sample, actual) end def similar?(a, b) @@ -202,28 +202,28 @@ matcher.matches?([2,3,1]).should be_true end it "supports fluent interface" do - matcher = Rspec::Matchers::Matcher.new(:first_word) do + matcher = RSpec::Matchers::Matcher.new(:first_word) do def second_word self end end matcher.second_word.should == matcher end it "treats method missing normally for undeclared methods" do - matcher = Rspec::Matchers::Matcher.new(:ignore) { } + matcher = RSpec::Matchers::Matcher.new(:ignore) { } expect { matcher.non_existent_method }.to raise_error(NoMethodError) end it "has access to other matchers" do - matcher = Rspec::Matchers::Matcher.new(:ignore, 3) do |expected| + matcher = RSpec::Matchers::Matcher.new(:ignore, 3) do |expected| match do |actual| - extend Rspec::Matchers + extend RSpec::Matchers actual.should eql(5 + expected) end end matcher.matches?(8).should be_true @@ -238,11 +238,11 @@ end end end let(:matcher) do m = mod - Rspec::Matchers::Matcher.new :equal, 4 do |expected| + RSpec::Matchers::Matcher.new :equal, 4 do |expected| extend m match_unless_raises UnexpectedError do assert_equal expected, actual end end @@ -255,11 +255,11 @@ end end context "with an unexpected error" do let(:matcher) do - Rspec::Matchers::Matcher.new :foo, :bar do |expected| + RSpec::Matchers::Matcher.new :foo, :bar do |expected| match_unless_raises SyntaxError do |actual| raise "unexpected exception" end end end @@ -272,11 +272,11 @@ end end it "can define chainable methods" do - matcher = Rspec::Matchers::Matcher.new(:name) do + matcher = RSpec::Matchers::Matcher.new(:name) do chain(:expecting) do |expected_value| @expected_value = expected_value end match { |actual| actual == @expected_value } end @@ -289,27 +289,27 @@ def a_method_in_the_example "method defined in the example" end it "can access methods in the running_example" do - Rspec::Matchers.define(:__access_running_example) do + RSpec::Matchers.define(:__access_running_example) do match do |actual| a_method_in_the_example == "method defined in the example" end end running_example.should __access_running_example end it "raises NoMethodError for methods not in the running_example" do - Rspec::Matchers.define(:__raise_no_method_error) do + RSpec::Matchers.define(:__raise_no_method_error) do match do |actual| a_method_not_in_the_example == "method defined in the example" end end expect do running_example.should __raise_no_method_error - end.to raise_error(/Rspec::Matchers::Matcher/) + end.to raise_error(/RSpec::Matchers::Matcher/) end end end end