diff options
author | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-05-07 12:04:49 +0000 |
---|---|---|
committer | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-05-07 12:04:49 +0000 |
commit | 95e8c48dd3348503a8c7db5d0498894a1b676395 (patch) | |
tree | 9eef7f720314ebaff56845a74e203770e62284e4 /spec/mspec/spec/matchers/base_spec.rb | |
parent | ed7d803500de38186c74bce94d233e85ef51e503 (diff) |
Add in-tree mspec and ruby/spec
* For easier modifications of ruby/spec by MRI developers.
* .gitignore: track changes under spec.
* spec/mspec, spec/rubyspec: add in-tree mspec and ruby/spec.
These files can therefore be updated like any other file in MRI.
Instructions are provided in spec/README.
[Feature #13156] [ruby-core:79246]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58595 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/mspec/spec/matchers/base_spec.rb')
-rw-r--r-- | spec/mspec/spec/matchers/base_spec.rb | 225 |
1 files changed, 225 insertions, 0 deletions
diff --git a/spec/mspec/spec/matchers/base_spec.rb b/spec/mspec/spec/matchers/base_spec.rb new file mode 100644 index 0000000000..cc13c29d1d --- /dev/null +++ b/spec/mspec/spec/matchers/base_spec.rb @@ -0,0 +1,225 @@ +require 'spec_helper' +require 'mspec/expectations/expectations' +require 'mspec/matchers' +require 'time' + +describe SpecPositiveOperatorMatcher, "== operator" do + it "raises an SpecExpectationNotMetError when expected == actual returns false" do + lambda { + SpecPositiveOperatorMatcher.new(1) == 2 + }.should raise_error(SpecExpectationNotMetError) + 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 + SpecPositiveOperatorMatcher.new(1) == 1 + end +end + +describe SpecPositiveOperatorMatcher, "=~ operator" do + it "raises an SpecExpectationNotMetError when expected =~ actual returns false" do + lambda { + SpecPositiveOperatorMatcher.new('real') =~ /fake/ + }.should raise_error(SpecExpectationNotMetError) + 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 + SpecPositiveOperatorMatcher.new('real') =~ /real/ + end +end + +describe SpecPositiveOperatorMatcher, "> operator" do + it "raises an SpecExpectationNotMetError when expected > actual returns false" do + lambda { + SpecPositiveOperatorMatcher.new(4) > 5 + }.should raise_error(SpecExpectationNotMetError) + 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 + SpecPositiveOperatorMatcher.new(5) > 4 + end +end + +describe SpecPositiveOperatorMatcher, ">= operator" do + it "raises an SpecExpectationNotMetError when expected >= actual returns false" do + lambda { + SpecPositiveOperatorMatcher.new(4) >= 5 + }.should raise_error(SpecExpectationNotMetError) + 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 + SpecPositiveOperatorMatcher.new(5) >= 4 + SpecPositiveOperatorMatcher.new(5) >= 5 + end +end + +describe SpecPositiveOperatorMatcher, "< operater" do + it "raises an SpecExpectationNotMetError when expected < actual returns false" do + lambda { + SpecPositiveOperatorMatcher.new(5) < 4 + }.should raise_error(SpecExpectationNotMetError) + 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 + SpecPositiveOperatorMatcher.new(4) < 5 + end +end + +describe SpecPositiveOperatorMatcher, "<= operater" do + it "raises an SpecExpectationNotMetError when expected < actual returns false" do + lambda { + SpecPositiveOperatorMatcher.new(5) <= 4 + }.should raise_error(SpecExpectationNotMetError) + 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 + SpecPositiveOperatorMatcher.new(4) <= 5 + SpecPositiveOperatorMatcher.new(4) <= 4 + end +end + +describe SpecNegativeOperatorMatcher, "== operator" do + it "raises an SpecExpectationNotMetError when expected == actual returns true" do + lambda { + SpecNegativeOperatorMatcher.new(1) == 1 + }.should raise_error(SpecExpectationNotMetError) + end + + 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 + end + + it "does not raise an exception when expected == actual returns false" do + SpecNegativeOperatorMatcher.new(1) == 2 + end +end + +describe SpecNegativeOperatorMatcher, "=~ operator" do + it "raises an SpecExpectationNotMetError when expected =~ actual returns true" do + lambda { + SpecNegativeOperatorMatcher.new('real') =~ /real/ + }.should raise_error(SpecExpectationNotMetError) + 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 + SpecNegativeOperatorMatcher.new('real') =~ /fake/ + end +end + +describe SpecNegativeOperatorMatcher, "< operator" do + it "raises an SpecExpectationNotMetError when expected < actual returns true" 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 + end + + it "does not raise an exception when expected < actual returns false" do + SpecNegativeOperatorMatcher.new(5) < 4 + end +end + +describe SpecNegativeOperatorMatcher, "<= operator" do + it "raises an SpecExpectationNotMetError when expected <= actual returns true" do + lambda { + SpecNegativeOperatorMatcher.new(4) <= 5 + }.should raise_error(SpecExpectationNotMetError) + 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 + end + + it "does not raise an exception when expected <= actual returns false" do + SpecNegativeOperatorMatcher.new(5) <= 4 + end +end + +describe SpecNegativeOperatorMatcher, "> operator" do + it "raises an SpecExpectationNotMetError when expected > actual returns true" 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 + end + + it "does not raise an exception when expected > actual returns false" do + SpecNegativeOperatorMatcher.new(4) > 5 + end +end + +describe SpecNegativeOperatorMatcher, ">= operator" do + it "raises an SpecExpectationNotMetError when expected >= actual returns true" do + lambda { + SpecNegativeOperatorMatcher.new(5) >= 4 + }.should raise_error(SpecExpectationNotMetError) + 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 + end + + it "does not raise an exception when expected >= actual returns false" do + SpecNegativeOperatorMatcher.new(4) >= 5 + end +end |