diff options
Diffstat (limited to 'spec/mspec/spec')
-rw-r--r-- | spec/mspec/spec/expectations/should_spec.rb | 8 | ||||
-rw-r--r-- | spec/mspec/spec/integration/run_spec.rb | 5 | ||||
-rw-r--r-- | spec/mspec/spec/integration/tag_spec.rb | 10 | ||||
-rw-r--r-- | spec/mspec/spec/matchers/base_spec.rb | 215 | ||||
-rw-r--r-- | spec/mspec/spec/matchers/eql_spec.rb | 4 | ||||
-rw-r--r-- | spec/mspec/spec/matchers/equal_element_spec.rb | 12 | ||||
-rw-r--r-- | spec/mspec/spec/matchers/equal_spec.rb | 4 | ||||
-rw-r--r-- | spec/mspec/spec/matchers/raise_error_spec.rb | 2 | ||||
-rw-r--r-- | spec/mspec/spec/spec_helper.rb | 2 |
9 files changed, 131 insertions, 131 deletions
diff --git a/spec/mspec/spec/expectations/should_spec.rb b/spec/mspec/spec/expectations/should_spec.rb index 3258caf13c..2c896f1c3b 100644 --- a/spec/mspec/spec/expectations/should_spec.rb +++ b/spec/mspec/spec/expectations/should_spec.rb @@ -14,8 +14,8 @@ describe "MSpec" do @out.should include <<-EOS 1) MSpec expectation method #should causes a failue to be recorded FAILED -Expected 1 - to equal 2 +Expected 1 == 2 +to be truthy but was false EOS end @@ -33,8 +33,8 @@ EOS @out.should include <<-EOS 3) MSpec expectation method #should_not causes a failure to be recorded FAILED -Expected 1 - not to equal 1 +Expected 1 == 1 +to be falsy but was true EOS end diff --git a/spec/mspec/spec/integration/run_spec.rb b/spec/mspec/spec/integration/run_spec.rb index dc2a9933f9..6703e83150 100644 --- a/spec/mspec/spec/integration/run_spec.rb +++ b/spec/mspec/spec/integration/run_spec.rb @@ -5,9 +5,8 @@ describe "Running mspec" do 1) Foo#bar errors FAILED -Expected 1 - to equal 2 - +Expected 1 == 2 +to be truthy but was false CWD/spec/fixtures/a_spec.rb:8:in `block (2 levels) in <top (required)>' CWD/spec/fixtures/a_spec.rb:2:in `<top (required)>' CWD/bin/mspec-run:7:in `<main>' diff --git a/spec/mspec/spec/integration/tag_spec.rb b/spec/mspec/spec/integration/tag_spec.rb index d980769043..1882d71e32 100644 --- a/spec/mspec/spec/integration/tag_spec.rb +++ b/spec/mspec/spec/integration/tag_spec.rb @@ -24,18 +24,16 @@ Tag#me érròrs in unicode 1) Tag#me errors FAILED -Expected 1 - to equal 2 - +Expected 1 == 2 +to be truthy but was false CWD/spec/fixtures/tagging_spec.rb:9:in `block (2 levels) in <top (required)>' CWD/spec/fixtures/tagging_spec.rb:3:in `<top (required)>' CWD/bin/mspec-tag:7:in `<main>' 2) Tag#me érròrs in unicode FAILED -Expected 1 - to equal 2 - +Expected 1 == 2 +to be truthy but was false CWD/spec/fixtures/tagging_spec.rb:13:in `block (2 levels) in <top (required)>' CWD/spec/fixtures/tagging_spec.rb:3:in `<top (required)>' CWD/bin/mspec-tag:7:in `<main>' diff --git a/spec/mspec/spec/matchers/base_spec.rb b/spec/mspec/spec/matchers/base_spec.rb index cc13c29d1d..4694d754f7 100644 --- a/spec/mspec/spec/matchers/base_spec.rb +++ b/spec/mspec/spec/matchers/base_spec.rb @@ -4,222 +4,225 @@ require 'mspec/matchers' require 'time' describe SpecPositiveOperatorMatcher, "== operator" do - it "raises an SpecExpectationNotMetError when expected == actual returns false" do + it "provides a failure message that 'Expected x to equal y'" do lambda { SpecPositiveOperatorMatcher.new(1) == 2 - }.should raise_error(SpecExpectationNotMetError) + }.should raise_error(SpecExpectationNotMetError, "Expected 1 == 2\nto be truthy but was false") end - it "provides a failure message that 'Expected x to equal y'" do - SpecExpectation.should_receive(:fail_with).with("Expected 1\n", "to equal 2\n") - SpecPositiveOperatorMatcher.new(1) == 2 - end - - it "does not raise an exception when expected == actual returns true" do + it "does not raise an exception when == returns true" do SpecPositiveOperatorMatcher.new(1) == 1 end end describe SpecPositiveOperatorMatcher, "=~ operator" do - it "raises an SpecExpectationNotMetError when expected =~ actual returns false" do + it "provides a failure message that 'Expected \"x\" to match y'" do lambda { SpecPositiveOperatorMatcher.new('real') =~ /fake/ - }.should raise_error(SpecExpectationNotMetError) + }.should raise_error(SpecExpectationNotMetError, "Expected \"real\" =~ /fake/\nto be truthy but was nil") end - it "provides a failure message that 'Expected \"x\" to match y'" do - SpecExpectation.should_receive(:fail_with).with( - "Expected \"real\"\n", "to match /fake/\n") - SpecPositiveOperatorMatcher.new('real') =~ /fake/ - end - - it "does not raise an exception when expected =~ actual returns true" do + it "does not raise an exception when =~ returns true" do SpecPositiveOperatorMatcher.new('real') =~ /real/ end end describe SpecPositiveOperatorMatcher, "> operator" do - it "raises an SpecExpectationNotMetError when expected > actual returns false" do + it "provides a failure message that 'Expected x to be greater than y'" do lambda { SpecPositiveOperatorMatcher.new(4) > 5 - }.should raise_error(SpecExpectationNotMetError) + }.should raise_error(SpecExpectationNotMetError, "Expected 4 > 5\nto be truthy but was false") end - it "provides a failure message that 'Expected x to be greater than y'" do - SpecExpectation.should_receive(:fail_with).with( - "Expected 4\n", "to be greater than 5\n") - SpecPositiveOperatorMatcher.new(4) > 5 - end - - it "does not raise an exception when expected > actual returns true" do + it "does not raise an exception when > returns true" do SpecPositiveOperatorMatcher.new(5) > 4 end end describe SpecPositiveOperatorMatcher, ">= operator" do - it "raises an SpecExpectationNotMetError when expected >= actual returns false" do + it "provides a failure message that 'Expected x to be greater than or equal to y'" do lambda { SpecPositiveOperatorMatcher.new(4) >= 5 - }.should raise_error(SpecExpectationNotMetError) + }.should raise_error(SpecExpectationNotMetError, "Expected 4 >= 5\nto be truthy but was false") end - it "provides a failure message that 'Expected x to be greater than or equal to y'" do - SpecExpectation.should_receive(:fail_with).with( - "Expected 4\n", "to be greater than or equal to 5\n") - SpecPositiveOperatorMatcher.new(4) >= 5 - end - - it "does not raise an exception when expected > actual returns true" do + it "does not raise an exception when > returns true" do SpecPositiveOperatorMatcher.new(5) >= 4 SpecPositiveOperatorMatcher.new(5) >= 5 end end describe SpecPositiveOperatorMatcher, "< operater" do - it "raises an SpecExpectationNotMetError when expected < actual returns false" do + it "provides a failure message that 'Expected x to be less than y'" do lambda { SpecPositiveOperatorMatcher.new(5) < 4 - }.should raise_error(SpecExpectationNotMetError) + }.should raise_error(SpecExpectationNotMetError, "Expected 5 < 4\nto be truthy but was false") end - it "provides a failure message that 'Expected x to be less than y'" do - SpecExpectation.should_receive(:fail_with).with("Expected 5\n", "to be less than 4\n") - SpecPositiveOperatorMatcher.new(5) < 4 - end - - it "does not raise an exception when expected < actual returns true" do + it "does not raise an exception when < returns true" do SpecPositiveOperatorMatcher.new(4) < 5 end end describe SpecPositiveOperatorMatcher, "<= operater" do - it "raises an SpecExpectationNotMetError when expected < actual returns false" do + it "provides a failure message that 'Expected x to be less than or equal to y'" do lambda { SpecPositiveOperatorMatcher.new(5) <= 4 - }.should raise_error(SpecExpectationNotMetError) + }.should raise_error(SpecExpectationNotMetError, "Expected 5 <= 4\nto be truthy but was false") end - it "provides a failure message that 'Expected x to be less than or equal to y'" do - SpecExpectation.should_receive(:fail_with).with( - "Expected 5\n", "to be less than or equal to 4\n") - SpecPositiveOperatorMatcher.new(5) <= 4 - end - - it "does not raise an exception when expected < actual returns true" do + it "does not raise an exception when < returns true" do SpecPositiveOperatorMatcher.new(4) <= 5 SpecPositiveOperatorMatcher.new(4) <= 4 end end -describe SpecNegativeOperatorMatcher, "== operator" do - it "raises an SpecExpectationNotMetError when expected == actual returns true" do +describe SpecPositiveOperatorMatcher, "arbitrary predicates" do + it "do not raise an exception when the predicate is truthy" do + SpecPositiveOperatorMatcher.new(2).eql?(2) + SpecPositiveOperatorMatcher.new(2).equal?(2) + SpecPositiveOperatorMatcher.new([1, 2, 3]).include?(2) + SpecPositiveOperatorMatcher.new("abc").start_with?("ab") + SpecPositiveOperatorMatcher.new("abc").start_with?("d", "a") + SpecPositiveOperatorMatcher.new(3).odd? + SpecPositiveOperatorMatcher.new([1, 2]).any? { |e| e.even? } + end + + it "provide a failure message when the predicate returns a falsy value" do lambda { - SpecNegativeOperatorMatcher.new(1) == 1 - }.should raise_error(SpecExpectationNotMetError) + SpecPositiveOperatorMatcher.new(2).eql?(3) + }.should raise_error(SpecExpectationNotMetError, "Expected 2.eql? 3\nto be truthy but was false") + lambda { + SpecPositiveOperatorMatcher.new(2).equal?(3) + }.should raise_error(SpecExpectationNotMetError, "Expected 2.equal? 3\nto be truthy but was false") + lambda { + SpecPositiveOperatorMatcher.new([1, 2, 3]).include?(4) + }.should raise_error(SpecExpectationNotMetError, "Expected [1, 2, 3].include? 4\nto be truthy but was false") + lambda { + SpecPositiveOperatorMatcher.new("abc").start_with?("de") + }.should raise_error(SpecExpectationNotMetError, "Expected \"abc\".start_with? \"de\"\nto be truthy but was false") + lambda { + SpecPositiveOperatorMatcher.new("abc").start_with?("d", "e") + }.should raise_error(SpecExpectationNotMetError, "Expected \"abc\".start_with? \"d\", \"e\"\nto be truthy but was false") + lambda { + SpecPositiveOperatorMatcher.new(2).odd? + }.should raise_error(SpecExpectationNotMetError, "Expected 2.odd?\nto be truthy but was false") + lambda { + SpecPositiveOperatorMatcher.new([1, 3]).any? { |e| e.even? } + }.should raise_error(SpecExpectationNotMetError, "Expected [1, 3].any? { ... }\nto be truthy but was false") + end +end + +describe SpecNegativeOperatorMatcher, "arbitrary predicates" do + it "do not raise an exception when the predicate returns a falsy value" do + SpecNegativeOperatorMatcher.new(2).eql?(3) + SpecNegativeOperatorMatcher.new(2).equal?(3) + SpecNegativeOperatorMatcher.new([1, 2, 3]).include?(4) + SpecNegativeOperatorMatcher.new("abc").start_with?("de") + SpecNegativeOperatorMatcher.new("abc").start_with?("d", "e") + SpecNegativeOperatorMatcher.new(2).odd? + SpecNegativeOperatorMatcher.new([1, 3]).any? { |e| e.even? } + end + + it "provide a failure message when the predicate returns a truthy value" do + lambda { + SpecNegativeOperatorMatcher.new(2).eql?(2) + }.should raise_error(SpecExpectationNotMetError, "Expected 2.eql? 2\nto be falsy but was true") + lambda { + SpecNegativeOperatorMatcher.new(2).equal?(2) + }.should raise_error(SpecExpectationNotMetError, "Expected 2.equal? 2\nto be falsy but was true") + lambda { + SpecNegativeOperatorMatcher.new([1, 2, 3]).include?(2) + }.should raise_error(SpecExpectationNotMetError, "Expected [1, 2, 3].include? 2\nto be falsy but was true") + lambda { + SpecNegativeOperatorMatcher.new("abc").start_with?("ab") + }.should raise_error(SpecExpectationNotMetError, "Expected \"abc\".start_with? \"ab\"\nto be falsy but was true") + lambda { + SpecNegativeOperatorMatcher.new("abc").start_with?("d", "a") + }.should raise_error(SpecExpectationNotMetError, "Expected \"abc\".start_with? \"d\", \"a\"\nto be falsy but was true") + lambda { + SpecNegativeOperatorMatcher.new(3).odd? + }.should raise_error(SpecExpectationNotMetError, "Expected 3.odd?\nto be falsy but was true") + lambda { + SpecNegativeOperatorMatcher.new([1, 2]).any? { |e| e.even? } + }.should raise_error(SpecExpectationNotMetError, "Expected [1, 2].any? { ... }\nto be falsy but was true") end +end +describe SpecNegativeOperatorMatcher, "== operator" do it "provides a failure message that 'Expected x not to equal y'" do - SpecExpectation.should_receive(:fail_with).with("Expected 1\n", "not to equal 1\n") - SpecNegativeOperatorMatcher.new(1) == 1 + lambda { + SpecNegativeOperatorMatcher.new(1) == 1 + }.should raise_error(SpecExpectationNotMetError, "Expected 1 == 1\nto be falsy but was true") end - it "does not raise an exception when expected == actual returns false" do + it "does not raise an exception when == returns false" do SpecNegativeOperatorMatcher.new(1) == 2 end end describe SpecNegativeOperatorMatcher, "=~ operator" do - it "raises an SpecExpectationNotMetError when expected =~ actual returns true" do + it "provides a failure message that 'Expected \"x\" not to match /y/'" do lambda { SpecNegativeOperatorMatcher.new('real') =~ /real/ - }.should raise_error(SpecExpectationNotMetError) + }.should raise_error(SpecExpectationNotMetError, "Expected \"real\" =~ /real/\nto be falsy but was 0") end - it "provides a failure message that 'Expected \"x\" not to match /y/'" do - SpecExpectation.should_receive(:fail_with).with( - "Expected \"real\"\n", "not to match /real/\n") - SpecNegativeOperatorMatcher.new('real') =~ /real/ - end - - it "does not raise an exception when expected =~ actual returns false" do + it "does not raise an exception when =~ returns false" do SpecNegativeOperatorMatcher.new('real') =~ /fake/ end end describe SpecNegativeOperatorMatcher, "< operator" do - it "raises an SpecExpectationNotMetError when expected < actual returns true" do + it "provides a failure message that 'Expected x not to be less than y'" do lambda { SpecNegativeOperatorMatcher.new(4) < 5 - }.should raise_error(SpecExpectationNotMetError) - end - - it "provides a failure message that 'Expected x not to be less than y'" do - SpecExpectation.should_receive(:fail_with).with( - "Expected 4\n", "not to be less than 5\n") - SpecNegativeOperatorMatcher.new(4) < 5 + }.should raise_error(SpecExpectationNotMetError, "Expected 4 < 5\nto be falsy but was true") end - it "does not raise an exception when expected < actual returns false" do + it "does not raise an exception when < returns false" do SpecNegativeOperatorMatcher.new(5) < 4 end end describe SpecNegativeOperatorMatcher, "<= operator" do - it "raises an SpecExpectationNotMetError when expected <= actual returns true" do + it "provides a failure message that 'Expected x not to be less than or equal to y'" do lambda { SpecNegativeOperatorMatcher.new(4) <= 5 - }.should raise_error(SpecExpectationNotMetError) + }.should raise_error(SpecExpectationNotMetError, "Expected 4 <= 5\nto be falsy but was true") lambda { SpecNegativeOperatorMatcher.new(5) <= 5 - }.should raise_error(SpecExpectationNotMetError) - end - - it "provides a failure message that 'Expected x not to be less than or equal to y'" do - SpecExpectation.should_receive(:fail_with).with( - "Expected 4\n", "not to be less than or equal to 5\n") - SpecNegativeOperatorMatcher.new(4) <= 5 + }.should raise_error(SpecExpectationNotMetError, "Expected 5 <= 5\nto be falsy but was true") end - it "does not raise an exception when expected <= actual returns false" do + it "does not raise an exception when <= returns false" do SpecNegativeOperatorMatcher.new(5) <= 4 end end describe SpecNegativeOperatorMatcher, "> operator" do - it "raises an SpecExpectationNotMetError when expected > actual returns true" do + it "provides a failure message that 'Expected x not to be greater than y'" do lambda { SpecNegativeOperatorMatcher.new(5) > 4 - }.should raise_error(SpecExpectationNotMetError) - end - - it "provides a failure message that 'Expected x not to be greater than y'" do - SpecExpectation.should_receive(:fail_with).with( - "Expected 5\n", "not to be greater than 4\n") - SpecNegativeOperatorMatcher.new(5) > 4 + }.should raise_error(SpecExpectationNotMetError, "Expected 5 > 4\nto be falsy but was true") end - it "does not raise an exception when expected > actual returns false" do + it "does not raise an exception when > returns false" do SpecNegativeOperatorMatcher.new(4) > 5 end end describe SpecNegativeOperatorMatcher, ">= operator" do - it "raises an SpecExpectationNotMetError when expected >= actual returns true" do + it "provides a failure message that 'Expected x not to be greater than or equal to y'" do lambda { SpecNegativeOperatorMatcher.new(5) >= 4 - }.should raise_error(SpecExpectationNotMetError) + }.should raise_error(SpecExpectationNotMetError, "Expected 5 >= 4\nto be falsy but was true") lambda { SpecNegativeOperatorMatcher.new(5) >= 5 - }.should raise_error(SpecExpectationNotMetError) - end - - it "provides a failure message that 'Expected x not to be greater than or equal to y'" do - SpecExpectation.should_receive(:fail_with).with( - "Expected 5\n", "not to be greater than or equal to 4\n") - SpecNegativeOperatorMatcher.new(5) >= 4 + }.should raise_error(SpecExpectationNotMetError, "Expected 5 >= 5\nto be falsy but was true") end - it "does not raise an exception when expected >= actual returns false" do + it "does not raise an exception when >= returns false" do SpecNegativeOperatorMatcher.new(4) >= 5 end end diff --git a/spec/mspec/spec/matchers/eql_spec.rb b/spec/mspec/spec/matchers/eql_spec.rb index 711ebdb679..f29e6976da 100644 --- a/spec/mspec/spec/matchers/eql_spec.rb +++ b/spec/mspec/spec/matchers/eql_spec.rb @@ -22,12 +22,12 @@ describe EqlMatcher do it "provides a useful failure message" do matcher = EqlMatcher.new("red") matcher.matches?("red") - matcher.failure_message.should == ["Expected \"red\"\n", "to have same value and type as \"red\"\n"] + matcher.failure_message.should == ["Expected \"red\"", "to have same value and type as \"red\""] end it "provides a useful negative failure message" do matcher = EqlMatcher.new(1) matcher.matches?(1.0) - matcher.negative_failure_message.should == ["Expected 1.0\n", "not to have same value or type as 1\n"] + matcher.negative_failure_message.should == ["Expected 1.0", "not to have same value or type as 1"] end end diff --git a/spec/mspec/spec/matchers/equal_element_spec.rb b/spec/mspec/spec/matchers/equal_element_spec.rb index 45b8390364..06fae762c4 100644 --- a/spec/mspec/spec/matchers/equal_element_spec.rb +++ b/spec/mspec/spec/matchers/equal_element_spec.rb @@ -48,28 +48,28 @@ describe EqualElementMatcher do it "provides a useful failure message" do equal_element = EqualElementMatcher.new("A", {}, "Test") equal_element.matches?('<A></A>').should be_false - equal_element.failure_message.should == [%{Expected "<A></A>"\n}, %{to be a 'A' element with no attributes and "Test" as content}] + equal_element.failure_message.should == [%{Expected "<A></A>"}, %{to be a 'A' element with no attributes and "Test" as content}] equal_element = EqualElementMatcher.new("A", {}, "") equal_element.matches?('<A>Test</A>').should be_false - equal_element.failure_message.should == [%{Expected "<A>Test</A>"\n}, %{to be a 'A' element with no attributes and no content}] + equal_element.failure_message.should == [%{Expected "<A>Test</A>"}, %{to be a 'A' element with no attributes and no content}] equal_element = EqualElementMatcher.new("A", "HREF" => "http://www.example.com") equal_element.matches?('<A>Test</A>').should be_false - equal_element.failure_message.should == [%{Expected "<A>Test</A>"\n}, %{to be a 'A' element with HREF="http://www.example.com" and any content}] + equal_element.failure_message.should == [%{Expected "<A>Test</A>"}, %{to be a 'A' element with HREF="http://www.example.com" and any content}] end it "provides a useful negative failure message" do equal_element = EqualElementMatcher.new("A", {}, "Test") equal_element.matches?('<A></A>').should be_false - equal_element.negative_failure_message.should == [%{Expected "<A></A>"\n}, %{not to be a 'A' element with no attributes and "Test" as content}] + equal_element.negative_failure_message.should == [%{Expected "<A></A>"}, %{not to be a 'A' element with no attributes and "Test" as content}] equal_element = EqualElementMatcher.new("A", {}, "") equal_element.matches?('<A>Test</A>').should be_false - equal_element.negative_failure_message.should == [%{Expected "<A>Test</A>"\n}, %{not to be a 'A' element with no attributes and no content}] + equal_element.negative_failure_message.should == [%{Expected "<A>Test</A>"}, %{not to be a 'A' element with no attributes and no content}] equal_element = EqualElementMatcher.new("A", "HREF" => "http://www.example.com") equal_element.matches?('<A>Test</A>').should be_false - equal_element.negative_failure_message.should == [%{Expected "<A>Test</A>"\n}, %{not to be a 'A' element with HREF="http://www.example.com" and any content}] + equal_element.negative_failure_message.should == [%{Expected "<A>Test</A>"}, %{not to be a 'A' element with HREF="http://www.example.com" and any content}] end end diff --git a/spec/mspec/spec/matchers/equal_spec.rb b/spec/mspec/spec/matchers/equal_spec.rb index ca7bf83fdd..a61432b750 100644 --- a/spec/mspec/spec/matchers/equal_spec.rb +++ b/spec/mspec/spec/matchers/equal_spec.rb @@ -21,12 +21,12 @@ describe EqualMatcher do it "provides a useful failure message" do matcher = EqualMatcher.new("red") matcher.matches?("red") - matcher.failure_message.should == ["Expected \"red\"\n", "to be identical to \"red\"\n"] + matcher.failure_message.should == ["Expected \"red\"", "to be identical to \"red\""] end it "provides a useful negative failure message" do matcher = EqualMatcher.new(1) matcher.matches?(1) - matcher.negative_failure_message.should == ["Expected 1\n", "not to be identical to 1\n"] + matcher.negative_failure_message.should == ["Expected 1", "not to be identical to 1"] end end diff --git a/spec/mspec/spec/matchers/raise_error_spec.rb b/spec/mspec/spec/matchers/raise_error_spec.rb index 28e1ea69a7..1ed794e0a9 100644 --- a/spec/mspec/spec/matchers/raise_error_spec.rb +++ b/spec/mspec/spec/matchers/raise_error_spec.rb @@ -111,7 +111,7 @@ describe RaiseErrorMatcher do matcher = RaiseErrorMatcher.new(ExpectedException, "expected") matcher.matches?(proc) matcher.failure_message.should == - ["Expected ExpectedException (expected)", "but no exception was raised (#pretty_inspect raised ArgumentError; A #<Object> was returned)"] + ["Expected ExpectedException (expected)", "but no exception was raised (#<Object>(#pretty_inspect raised #<ArgumentError: bad>) was returned)"] end it "provides a useful negative failure message" do diff --git a/spec/mspec/spec/spec_helper.rb b/spec/mspec/spec/spec_helper.rb index 0d497f6627..a307eaf460 100644 --- a/spec/mspec/spec/spec_helper.rb +++ b/spec/mspec/spec/spec_helper.rb @@ -1,4 +1,4 @@ -require 'pp' +require 'mspec/utils/format' require 'mspec/helpers/io' require 'mspec/helpers/scratch' |