spec/rspec/expectations/fail_with_spec.rb in rspec-expectations-2.12.1 vs spec/rspec/expectations/fail_with_spec.rb in rspec-expectations-2.13.0

- old
+ new

@@ -1,5 +1,6 @@ +# encoding: utf-8 require 'spec_helper' describe RSpec::Expectations, "#fail_with with diff" do let(:differ) { double("differ") } @@ -7,64 +8,88 @@ RSpec::Expectations.stub(:differ) { differ } end it "calls differ if expected/actual are not strings (or numbers or procs)" do differ.should_receive(:diff_as_object).and_return("diff") - lambda { + expect { RSpec::Expectations.fail_with "the message", Object.new, Object.new - }.should fail_with("the message\nDiff:diff") + }.to fail_with("the message\nDiff:diff") end context "with two strings" do context "and actual is multiline" do it "calls differ" do differ.should_receive(:diff_as_string).and_return("diff") - lambda { + expect { RSpec::Expectations.fail_with "the message", "expected\nthis", "actual" - }.should fail_with("the message\nDiff:diff") + }.to fail_with("the message\nDiff:diff") end end context "and expected is multiline" do it "calls differ" do differ.should_receive(:diff_as_string).and_return("diff") - lambda { + expect { RSpec::Expectations.fail_with "the message", "expected", "actual\nthat" - }.should fail_with("the message\nDiff:diff") + }.to fail_with("the message\nDiff:diff") end end context "and both are single line strings" do it "does not call differ" do differ.should_not_receive(:diff_as_string) - lambda { + expect { RSpec::Expectations.fail_with("the message", "expected", "actual") - }.should fail_with("the message") + }.to fail_with("the message") end end + + context "and they are UTF-16LE encoded", :if => String.method_defined?(:encode) do + it 'does not diff when they are not multiline' do + differ.should_not_receive(:diff_as_string) + + str_1 = "This is a pile of poo: šŸ’©".encode("UTF-16LE") + str_2 = "This is a pile of poo: šŸ’©".encode("UTF-16LE") + + expect { + RSpec::Expectations.fail_with("the message", str_1, str_2) + }.to fail_with("the message") + end + + it 'diffs when they are multiline' do + differ.should_receive(:diff_as_string).and_return("diff") + + str_1 = "This is a pile of poo:\nšŸ’©".encode("UTF-16LE") + str_2 = "This is a pile of poo:\nšŸ’©".encode("UTF-16LE") + + expect { + RSpec::Expectations.fail_with("the message", str_1, str_2) + }.to fail_with("the message\nDiff:diff") + end + end end it "does not call differ if no expected/actual" do - lambda { + expect { RSpec::Expectations.fail_with "the message" - }.should fail_with("the message") + }.to fail_with("the message") end it "does not call differ expected is Numeric" do - lambda { + expect { RSpec::Expectations.fail_with "the message", 1, "1" - }.should fail_with("the message") + }.to fail_with("the message") end it "does not call differ when actual is Numeric" do - lambda { + expect { RSpec::Expectations.fail_with "the message", "1", 1 - }.should fail_with("the message") + }.to fail_with("the message") end it "does not call differ if expected or actual are procs" do - lambda { + expect { RSpec::Expectations.fail_with "the message", lambda {}, lambda {} - }.should fail_with("the message") + }.to fail_with("the message") end end