Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: rspec/rspec-expectations
...
head fork: rspec/rspec-expectations
  • 16 commits
  • 25 files changed
  • 0 commit comments
  • 3 contributors
Commits on Oct 16, 2010
@myronmarston myronmarston Add cuke for be_kind_of and be_instance_of matchers.
- Closes #31.
8af48c0
@dchelimsky dchelimsky words dbdf3fc
Commits on Oct 18, 2010
@dchelimsky dchelimsky update versions 98d979c
Commits on Oct 19, 2010
@dchelimsky dchelimsky bump version to 2.0.1 17bb9b9
@dchelimsky dchelimsky update history 4b87326
@dchelimsky dchelimsky bump version to 2.0.2.pre 281bd6a
Commits on Oct 21, 2010
@dchelimsky dchelimsky resolve cross-repo dependency issues 290274f
Commits on Oct 22, 2010
@myronmarston myronmarston Improve failure messages for throw_symbol matcher and add a cuke for it. bf16b2b
Commits on Oct 23, 2010
@dchelimsky dchelimsky links to docs 3642020
@myronmarston myronmarston Add cuke for exist matcher. 32e3f9f
@myronmarston myronmarston Fix matcher chaining to prevent name collisions.
Previously, #chain used #define_method on the class to define an instance method on all instances.  We want it to define the method on only this instance, so we need to delegate to the singleton class instead (which the recently added #define_method does for us!).
9c2971a
@myronmarston myronmarston Fix `expect { ... }.to` so that it has no dependency on rspec-core an…
…d can work outside of it.

- Closes #37.
9393080
@myronmarston myronmarston Add cuke for satisfy matcher. abc0ef4
@dchelimsky dchelimsky update for relish e852032
Commits on Nov 06, 2010
@myronmarston myronmarston Raise an error if should/should_not !=/!~ is used since these operato…
…rs cannot be supported on ruby 1.8.

- Closes #33.
0e46795
@txus txus have_matcher - use pluralize only when ActiveSupport inflections are …
…indeed defined

- Closes #30.
1196f93
View
11 Gemfile
@@ -1,13 +1,14 @@
source "http://rubygems.org"
+%w[rspec-core rspec-expectations rspec-mocks].each do |lib|
+ gem lib, :path => File.expand_path("../../#{lib}", __FILE__)
+end
+
gem "rake"
-gem "cucumber"
-gem "aruba", ">= 0.2.0"
+gem "cucumber", "0.8.5"
+gem "aruba", "0.2.2"
gem "autotest"
gem "diff-lcs"
-gem "rspec-expectations", :path => "."
-gem "rspec-core", :path => "../rspec-core"
-gem "rspec-mocks", :path => "../rspec-mocks"
gem "watchr"
gem "rcov"
gem "relish"
View
7 History.markdown
@@ -1,5 +1,12 @@
## rspec-expectations release history (incomplete)
+### 2.0.1 / 2010-10-18
+
+[full changelog](http://github.com/rspec/rspec-expectations/compare/v2.0.0...v2.0.1)
+
+* Enhancements
+ * Make dependencies on other rspec gems consistent across gems
+
### 2.0.0 / 2010-10-10
[full changelog](http://github.com/rspec/rspec-expectations/compare/v2.0.0.rc...v2.0.0)
View
10 README.markdown
@@ -3,6 +3,16 @@
rspec-expectations adds `should` and `should_not` to every object and includes
RSpec::Matchers, a library of standard matchers.
+## Documentation
+
+* [Cucumber features](http://relishapp.com/rspec/rspec-expectations/v/2-0)
+* [RDoc](http://rubydoc.info/gems/rspec-expectations/2.0.1/frames)
+
+## Install
+
+ gem install rspec # for rspec-core, rspec-expectations, rspec-mocks
+ gem install rspec-expecctations # for rspec-core only
+
## Matchers
Matchers are objects used to compose expectations:
View
2  Rakefile
@@ -58,7 +58,7 @@ end
desc "Push cukes to relishapp using the relish-client-gem"
task :relish, :version do |t, args|
raise "rake relish[VERSION]" unless args[:version]
- sh "bundle exec relish --organization rspec --project rspec-expectations -v #{args[:version]} push"
+ sh "bundle exec relish push --organization rspec --project rspec-expectations -v #{args[:version]}"
end
task :clobber do
View
44 features/matchers/exist.feature
@@ -0,0 +1,44 @@
+Feature: exist matcher
+
+ The exist matcher is used to specify that something exists
+ (as indicated by #exist?):
+
+ obj.should exist # passes if obj.exist?
+
+ Scenario: basic usage
+ Given a file named "exist_matcher_spec.rb" with:
+ """
+ class Planet
+ attr_reader :name
+
+ def initialize(name)
+ @name = name
+ end
+
+ def inspect
+ "<Planet: #{name}>"
+ end
+
+ def exist?
+ %w[Mercury Venus Earth Mars Jupiter Saturn Uranus Neptune].include?(name)
+ end
+ end
+
+ describe "Earth" do
+ subject { Planet.new("Earth") }
+ it { should exist }
+ it { should_not exist } # deliberate failure
+ end
+
+ describe "Tatooine" do
+ subject { Planet.new("Tatooine") }
+ it { should_not exist }
+ it { should exist } # deliberate failure
+ end
+ """
+ When I run "rspec exist_matcher_spec.rb"
+ Then the output should contain all of these:
+ | 4 examples, 2 failures |
+ | expected <Planet: Earth> not to exist |
+ | expected <Planet: Tatooine> to exist |
+
View
31 features/matchers/satisfy.feature
@@ -0,0 +1,31 @@
+Feature: Satisfy matcher
+
+ The satisfy matcher is extremely flexible and can handle almost anything
+ you want to specify. It passes if the block you provide returns true:
+
+ 10.should satisfy { |v| v % 5 == 0 }
+ 7.should_not satisfy { |v| v % 5 == 0 }
+
+ This flexibility comes at a cost, however: the failure message
+ ("expected [actual] to satisfy block") is not very descriptive
+ or helpful. You will usually be better served by using one of
+ the other built-in matchers, or writing a custom matcher.
+
+ Scenario: basic usage
+ Given a file named "satisfy_matcher_spec.rb" with:
+ """
+ describe 10 do
+ it { should satisfy { |v| v > 5 } }
+ it { should_not satisfy { |v| v > 15 } }
+
+ # deliberate failures
+ it { should_not satisfy { |v| v > 5 } }
+ it { should satisfy { |v| v > 15 } }
+ end
+ """
+ When I run "rspec satisfy_matcher_spec.rb"
+ Then the output should contain all of these:
+ | 4 examples, 2 failures |
+ | expected 10 not to satisfy block |
+ | expected 10 to satisfy block |
+
View
85 features/matchers/throw_symbol.feature
@@ -0,0 +1,85 @@
+Feature: Throw symbol matcher
+
+ The throw_symbol matcher is used to specify that a block of code
+ throws a symbol. The most basic form passes if any symbol is thrown:
+
+ expect { throw :foo }.to throw_symbol
+
+ You'll often want to specify that a particular symbol is thrown:
+
+ expect { throw :foo }.to throw_symbol(:foo)
+
+ If you care about the additional argument given to throw, you can
+ specify that as well:
+
+ expect { throw :foo, 7 }.to throw_symbol(:foo, 7)
+
+ Scenario: basic usage
+ Given a file named "throw_symbol_matcher_spec.rb" with:
+ """
+ describe "throw" do
+ specify { expect { throw :foo }.to throw_symbol }
+ specify { expect { throw :bar, 7 }.to throw_symbol }
+ specify { expect { 5 + 5 }.to_not throw_symbol }
+
+ # deliberate failures
+ specify { expect { throw :foo }.to_not throw_symbol }
+ specify { expect { throw :bar, 7 }.to_not throw_symbol }
+ specify { expect { 5 + 5 }.to throw_symbol }
+ end
+ """
+ When I run "rspec throw_symbol_matcher_spec.rb"
+ Then the output should contain all of these:
+ | 6 examples, 3 failures |
+ | expected no Symbol to be thrown, got :foo |
+ | expected no Symbol to be thrown, got :bar |
+ | expected a Symbol to be thrown, got nothing |
+
+ Scenario: specify thrown symbol
+ Given a file named "throw_symbol_matcher_spec.rb" with:
+ """
+ describe "throw symbol" do
+ specify { expect { throw :foo }.to throw_symbol(:foo) }
+ specify { expect { throw :foo, 7 }.to throw_symbol(:foo) }
+ specify { expect { 5 + 5 }.to_not throw_symbol(:foo) }
+ specify { expect { throw :bar }.to_not throw_symbol(:foo) }
+
+ # deliberate failures
+ specify { expect { throw :foo }.to_not throw_symbol(:foo) }
+ specify { expect { throw :foo, 7 }.to_not throw_symbol(:foo) }
+ specify { expect { 5 + 5 }.to throw_symbol(:foo) }
+ specify { expect { throw :bar }.to throw_symbol(:foo) }
+ end
+ """
+ When I run "rspec throw_symbol_matcher_spec.rb"
+ Then the output should contain all of these:
+ | 8 examples, 4 failures |
+ | expected :foo not to be thrown, got :foo |
+ | expected :foo not to be thrown, got :foo with 7 |
+ | expected :foo to be thrown, got nothing |
+ | expected :foo to be thrown, got :bar |
+
+ Scenario: specify thrown symbol and argument
+ Given a file named "throw_symbol_argument_matcher_spec.rb" with:
+ """
+ describe "throw symbol with argument" do
+ specify { expect { throw :foo, 7 }.to throw_symbol(:foo, 7) }
+ specify { expect { throw :foo, 8 }.to_not throw_symbol(:foo, 7) }
+ specify { expect { throw :bar, 7 }.to_not throw_symbol(:foo, 7) }
+ specify { expect { throw :foo }.to_not throw_symbol(:foo, 7) }
+
+ # deliberate failures
+ specify { expect { throw :foo, 7 }.to_not throw_symbol(:foo, 7) }
+ specify { expect { throw :foo, 8 }.to throw_symbol(:foo, 7) }
+ specify { expect { throw :bar, 7 }.to throw_symbol(:foo, 7) }
+ specify { expect { throw :foo }.to throw_symbol(:foo, 7) }
+ end
+ """
+ When I run "rspec throw_symbol_argument_matcher_spec.rb"
+ Then the output should contain all of these:
+ | 8 examples, 4 failures |
+ | expected :foo with 7 not to be thrown, got :foo with 7 |
+ | expected :foo with 7 to be thrown, got :foo with 8 |
+ | expected :foo with 7 to be thrown, got :bar |
+ | expected :foo with 7 to be thrown, got :foo with no argument |
+
View
114 features/matchers/types.feature
@@ -0,0 +1,114 @@
+Feature: Type Check matchers
+
+ rspec-expectations includes two matchers specify types of objects:
+
+ * obj.should be_kind_of(type): calls obj.kind_of?(type), which returns
+ true if type is in obj's class hierarchy or is a module and is
+ included in a class in obj's class hierarchy.
+ * obj.should be_instance_of(type): calls obj.instance_of?(type), which
+ returns true if and only if type if obj's class.
+
+ Both of these matchers have aliases:
+
+ * obj.should be_a_kind_of(type) # same as obj.should be_kind_of(type)
+ * obj.should be_a(type) # same as obj.should be_kind_of(type)
+ * obj.should be_an(type) # same as obj.should be_kind_of(type)
+ * obj.should be_an_instance_of(type) # same as obj.should be_instance_of(type)
+
+ Scenario: be_(a_)kind_of matcher
+ Given a file named "be_kind_of_matcher_spec.rb" with:
+ """
+ module MyModule; end
+
+ class Fixnum
+ include MyModule
+ end
+
+ describe 17 do
+ # the actual class
+ it { should be_kind_of(Fixnum) }
+ it { should be_a_kind_of(Fixnum) }
+ it { should be_a(Fixnum) }
+
+ # the superclass
+ it { should be_kind_of(Integer) }
+ it { should be_a_kind_of(Integer) }
+ it { should be_an(Integer) }
+
+ # an included module
+ it { should be_kind_of(MyModule) }
+ it { should be_a_kind_of(MyModule) }
+ it { should be_a(MyModule) }
+
+ # negative passing case
+ it { should_not be_kind_of(String) }
+ it { should_not be_a_kind_of(String) }
+ it { should_not be_a(String) }
+
+ # deliberate failures
+ it { should_not be_kind_of(Fixnum) }
+ it { should_not be_a_kind_of(Fixnum) }
+ it { should_not be_a(Fixnum) }
+ it { should_not be_kind_of(Integer) }
+ it { should_not be_a_kind_of(Integer) }
+ it { should_not be_an(Integer) }
+ it { should_not be_kind_of(MyModule) }
+ it { should_not be_a_kind_of(MyModule) }
+ it { should_not be_a(MyModule) }
+ it { should be_kind_of(String) }
+ it { should be_a_kind_of(String) }
+ it { should be_a(String) }
+ end
+ """
+ When I run "rspec be_kind_of_matcher_spec.rb"
+ Then the output should contain all of these:
+ | 24 examples, 12 failures |
+ | expected 17 not to be a kind of Fixnum |
+ | expected 17 not to be a kind of Integer |
+ | expected 17 not to be a kind of MyModule |
+ | expected 17 to be a kind of String |
+
+ Scenario: be_(an_)instance_of matcher
+ Given a file named "be_instance_of_matcher_spec.rb" with:
+ """
+ module MyModule; end
+
+ class Fixnum
+ include MyModule
+ end
+
+ describe 17 do
+ # the actual class
+ it { should be_instance_of(Fixnum) }
+ it { should be_an_instance_of(Fixnum) }
+
+ # the superclass
+ it { should_not be_instance_of(Integer) }
+ it { should_not be_an_instance_of(Integer) }
+
+ # an included module
+ it { should_not be_instance_of(MyModule) }
+ it { should_not be_an_instance_of(MyModule) }
+
+ # another class with no relation to the subject's hierarchy
+ it { should_not be_instance_of(String) }
+ it { should_not be_an_instance_of(String) }
+
+ # deliberate failures
+ it { should_not be_instance_of(Fixnum) }
+ it { should_not be_an_instance_of(Fixnum) }
+ it { should be_instance_of(Integer) }
+ it { should be_an_instance_of(Integer) }
+ it { should be_instance_of(MyModule) }
+ it { should be_an_instance_of(MyModule) }
+ it { should be_instance_of(String) }
+ it { should be_an_instance_of(String) }
+ end
+ """
+ When I run "rspec be_instance_of_matcher_spec.rb"
+ Then the output should contain all of these:
+ | 16 examples, 8 failures |
+ | expected 17 not to be an instance of Fixnum |
+ | expected 17 to be an instance of Integer |
+ | expected 17 to be an instance of MyModule |
+ | expected 17 to be an instance of String |
View
6 features/test_frameworks/test_unit.feature
@@ -31,12 +31,16 @@ Feature: Test::Unit integration
array.should be_empty
end
+ def test_expect_matcher
+ expect { @a = 5 }.to change { @a }.from(nil).to(5)
+ end
+
def test_custom_matcher_and_deprecation_warning
1.should be_an_int
end
end
"""
When I run "ruby rspec_expectations_test.rb"
- Then the output should contain "3 tests, 0 assertions, 1 failures, 0 errors" or "3 tests, 0 assertions, 0 failures, 1 errors"
+ Then the output should contain "4 tests, 0 assertions, 1 failures, 0 errors" or "4 tests, 0 assertions, 0 failures, 1 errors"
And the output should contain "expected empty? to return true, got false"
And the output should contain "be_an_int is deprecated"
View
2  lib/rspec/expectations.rb
@@ -1,8 +1,8 @@
+require 'rspec/expectations/extensions'
require 'rspec/matchers'
require 'rspec/expectations/fail_with'
require 'rspec/expectations/errors'
require 'rspec/expectations/deprecation'
-require 'rspec/expectations/extensions'
require 'rspec/expectations/handler'
require 'rspec/expectations/version'
require 'rspec/expectations/backward_compatibility'
View
1  lib/rspec/expectations/extensions.rb
@@ -1,3 +1,2 @@
require 'rspec/expectations/extensions/kernel'
require 'rspec/expectations/extensions/array'
-require 'rspec/expectations/extensions/rspec/core/example_group'
View
19 lib/rspec/expectations/extensions/rspec/core/example_group.rb
@@ -1,19 +0,0 @@
-module RSpec
- module Core
- class ExampleGroup
- module BlockAliases
- alias_method :to, :should
- alias_method :to_not, :should_not
- end
-
- # Extends the submitted block with aliases to and to_not
- # for should and should_not. Allows expectations like this:
- #
- # expect { this_block }.to change{this.expression}.from(old_value).to(new_value)
- # expect { this_block }.to raise_error
- def expect(&block)
- block.extend BlockAliases
- end
- end
- end
-end
View
2  lib/rspec/expectations/version.rb
@@ -1,7 +1,7 @@
module RSpec # :nodoc:
module Expectations # :nodoc:
module Version # :nodoc:
- STRING = '2.0.0'
+ STRING = '2.0.2.pre'
end
end
end
View
1  lib/rspec/matchers.rb
@@ -177,6 +177,7 @@ module Matchers
require 'rspec/matchers/be_close'
require 'rspec/matchers/be_instance_of'
require 'rspec/matchers/be_kind_of'
+require 'rspec/matchers/block_aliases'
require 'rspec/matchers/change'
require 'rspec/matchers/eq'
require 'rspec/matchers/eql'
View
18 lib/rspec/matchers/block_aliases.rb
@@ -0,0 +1,18 @@
+module RSpec
+ module Matchers
+ module BlockAliases
+ alias_method :to, :should
+ alias_method :to_not, :should_not
+ end
+
+ # Extends the submitted block with aliases to and to_not
+ # for should and should_not. Allows expectations like this:
+ #
+ # expect { this_block }.to change{this.expression}.from(old_value).to(new_value)
+ # expect { this_block }.to raise_error
+ def expect(&block)
+ block.extend BlockAliases
+ end
+ end
+end
+
View
2  lib/rspec/matchers/have.rb
@@ -75,7 +75,7 @@ def respond_to?(sym)
def method_missing(sym, *args, &block)
@collection_name = sym
- if inflector = (defined?(ActiveSupport::Inflector) ? ActiveSupport::Inflector : (defined?(Inflector) ? Inflector : nil))
+ if inflector = (defined?(ActiveSupport::Inflector) && ActiveSupport::Inflector.respond_to?(:pluralize) ? ActiveSupport::Inflector : (defined?(Inflector) ? Inflector : nil))
@plural_collection_name = inflector.pluralize(sym.to_s)
end
@args = args
View
8 lib/rspec/matchers/matcher.rb
@@ -97,11 +97,9 @@ def diffable
# See RSpec::Matchers
def chain(method, &block)
- self.class.class_eval do
- define_method method do |*args|
- block.call(*args)
- self
- end
+ define_method method do |*args|
+ block.call(*args)
+ self
end
end
View
9 lib/rspec/matchers/operator_matcher.rb
@@ -29,6 +29,15 @@ def self.use_custom_matcher_or_delegate(operator)
eval_match(@actual, operator, expected)
end
end
+
+ negative_operator = operator.sub(/^=/, '!')
+ if negative_operator != operator && respond_to?(negative_operator)
+ define_method(negative_operator) do |expected|
+ opposite_should = ::RSpec::Matchers.last_should == :should ? :should_not : :should
+ raise "RSpec does not support `#{::RSpec::Matchers.last_should} #{negative_operator} expected`. " +
+ "Use `#{opposite_should} #{operator} expected` instead."
+ end
+ end
end
['==', '===', '=~', '>', '>=', '<', '<='].each do |operator|
View
47 lib/rspec/matchers/throw_symbol.rb
@@ -19,7 +19,12 @@ def matches?(given_proc)
throw :proc_did_not_throw_anything, :nothing_thrown
end
end
- @caught_symbol = @expected_symbol unless @caught_arg == :nothing_thrown
+
+ if @caught_arg == :nothing_thrown
+ @caught_arg = nil
+ else
+ @caught_symbol = @expected_symbol
+ end
end
# Ruby 1.8 uses NameError with `symbol'
@@ -42,19 +47,11 @@ def matches?(given_proc)
end
def failure_message_for_should
- if @caught_symbol
- "expected #{expected}, got #{@caught_symbol.inspect}"
- else
- "expected #{expected} but nothing was thrown"
- end
+ "expected #{expected} to be thrown, got #{caught}"
end
def failure_message_for_should_not
- if @expected_symbol
- "expected #{expected} not to be thrown"
- else
- "expected no Symbol, got :#{@caught_symbol}"
- end
+ "expected #{expected('no Symbol')}#{' not' if @expected_symbol} to be thrown, got #{caught}"
end
def description
@@ -62,15 +59,29 @@ def description
end
private
-
- def expected
- @expected_symbol.nil? ? "a Symbol" : "#{@expected_symbol.inspect}#{args}"
+
+ def expected(symbol_desc = 'a Symbol')
+ throw_description(@expected_symbol || symbol_desc, @expected_arg)
+ end
+
+ def caught
+ throw_description(@caught_symbol || 'nothing', @caught_arg)
end
-
- def args
- @expected_arg.nil? ? "" : " with #{@expected_arg.inspect}"
+
+ def throw_description(symbol, arg)
+ symbol_description = symbol.is_a?(String) ? symbol : symbol.inspect
+
+ arg_description = if arg
+ " with #{arg.inspect}"
+ elsif @expected_arg && @caught_symbol == @expected_symbol
+ " with no argument"
+ else
+ ""
+ end
+
+ symbol_description + arg_description
end
-
+
end
# :call-seq:
View
4 rspec-expectations.gemspec
@@ -25,7 +25,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency 'diff-lcs', '>= 1.1.2'
s.add_development_dependency 'cucumber', ">= 0.6.2"
s.add_development_dependency 'aruba', ">= 0.1.1"
- s.add_development_dependency 'rspec-core', ">= #{RSpec::Expectations::Version::STRING}"
- s.add_development_dependency 'rspec-mocks', ">= #{RSpec::Expectations::Version::STRING}"
+ s.add_development_dependency 'rspec-core', "~> 2.0.2.pre"
+ s.add_development_dependency 'rspec-mocks', "~> 2.0.2.pre"
end
View
12 spec/rspec/matchers/have_spec.rb
@@ -4,7 +4,7 @@
describe "have matcher" do
before(:each) do
- if defined?(::ActiveSupport::Inflector)
+ if defined?(::ActiveSupport::Inflector) && ::ActiveSupport::Inflector.respond_to?(:pluralize)
@active_support_was_defined = true
else
@active_support_was_defined = false
@@ -68,6 +68,16 @@ def create_collection_owner_with(n)
owner = create_collection_owner_with(1)
owner.should have(1).item
end
+
+ context "when ActiveSupport::Inflector is partially loaded without its inflectors" do
+
+ it "does not pluralize the collection name" do
+ (class << ::ActiveSupport::Inflector; self; end).send :undef_method, :pluralize
+ owner = create_collection_owner_with(1)
+ expect { owner.should have(1).item }.to raise_error(NoMethodError)
+ end
+
+ end
after(:each) do
unless @active_support_was_defined
View
8 spec/rspec/matchers/matcher_spec.rb
@@ -334,6 +334,14 @@ def assert_equal(a,b)
matcher.expecting('value').matches?('other value').should be_false
end
+ it "prevents name collisions on chainable methods from different matchers" do
+ m1 = RSpec::Matchers::Matcher.new(:m1) { chain(:foo) { raise "foo in m1" } }
+ m2 = RSpec::Matchers::Matcher.new(:m2) { chain(:foo) { raise "foo in m2" } }
+
+ expect { m1.foo }.to raise_error("foo in m1")
+ expect { m2.foo }.to raise_error("foo in m2")
+ end
+
context "defined using the dsl" do
def a_method_in_the_example
"method defined in the example"
View
26 spec/rspec/matchers/operator_matcher_spec.rb
@@ -21,6 +21,32 @@
end
+describe "unsupported operators", :ruby => '1.9' do
+ it "raises an appropriate error for should != expected" do
+ expect {
+ "apple".should != "pear"
+ }.to raise_error(/does not support `should != expected`. Use `should_not == expected`/)
+ end
+
+ it "raises an appropriate error for should_not != expected" do
+ expect {
+ "apple".should_not != "pear"
+ }.to raise_error(/does not support `should_not != expected`. Use `should == expected`/)
+ end
+
+ it "raises an appropriate error for should !~ expected" do
+ expect {
+ "apple".should !~ /regex/
+ }.to raise_error(/does not support `should !~ expected`. Use `should_not =~ expected`/)
+ end
+
+ it "raises an appropriate error for should_not !~ expected" do
+ expect {
+ "apple".should_not !~ /regex/
+ }.to raise_error(/does not support `should_not !~ expected`. Use `should =~ expected`/)
+ end
+end
+
describe "should_not ==" do
it "delegates message to target" do
View
24 spec/rspec/matchers/throw_symbol_spec.rb
@@ -17,11 +17,11 @@ module Matchers
end
it "provides a failure message" do
@matcher.matches?(lambda{})
- @matcher.failure_message_for_should.should == "expected a Symbol but nothing was thrown"
+ @matcher.failure_message_for_should.should == "expected a Symbol to be thrown, got nothing"
end
it "provides a negative failure message" do
@matcher.matches?(lambda{ throw :sym})
- @matcher.failure_message_for_should_not.should == "expected no Symbol, got :sym"
+ @matcher.failure_message_for_should_not.should == "expected no Symbol to be thrown, got :sym"
end
end
@@ -42,15 +42,15 @@ module Matchers
end
it "provides a failure message when no Symbol is thrown" do
@matcher.matches?(lambda{})
- @matcher.failure_message_for_should.should == "expected :sym but nothing was thrown"
+ @matcher.failure_message_for_should.should == "expected :sym to be thrown, got nothing"
end
it "provides a failure message when wrong Symbol is thrown" do
@matcher.matches?(lambda{ throw :other_sym })
- @matcher.failure_message_for_should.should == "expected :sym, got :other_sym"
+ @matcher.failure_message_for_should.should == "expected :sym to be thrown, got :other_sym"
end
it "provides a negative failure message" do
@matcher.matches?(lambda{ throw :sym })
- @matcher.failure_message_for_should_not.should == "expected :sym not to be thrown"
+ @matcher.failure_message_for_should_not.should == "expected :sym not to be thrown, got :sym"
end
it "only matches NameErrors raised by uncaught throws" do
@matcher.matches?(lambda{ sym }).should be_false
@@ -77,15 +77,23 @@ module Matchers
end
it "provides a failure message when no Symbol is thrown" do
@matcher.matches?(lambda{})
- @matcher.failure_message_for_should.should == %q[expected :sym with "a" but nothing was thrown]
+ @matcher.failure_message_for_should.should == %q[expected :sym with "a" to be thrown, got nothing]
end
it "provides a failure message when wrong Symbol is thrown" do
@matcher.matches?(lambda{ throw :other_sym })
- @matcher.failure_message_for_should.should == %q[expected :sym with "a", got :other_sym]
+ @matcher.failure_message_for_should.should == %q[expected :sym with "a" to be thrown, got :other_sym]
+ end
+ it "provides a failure message when wrong arg is thrown" do
+ @matcher.matches?(lambda{ throw :sym, "b" })
+ @matcher.failure_message_for_should.should == %q[expected :sym with "a" to be thrown, got :sym with "b"]
+ end
+ it "provides a failure message when no arg is thrown" do
+ @matcher.matches?(lambda{ throw :sym })
+ @matcher.failure_message_for_should.should == %q[expected :sym with "a" to be thrown, got :sym with no argument]
end
it "provides a negative failure message" do
@matcher.matches?(lambda{ throw :sym })
- @matcher.failure_message_for_should_not.should == %q[expected :sym with "a" not to be thrown]
+ @matcher.failure_message_for_should_not.should == %q[expected :sym with "a" not to be thrown, got :sym with no argument]
end
it "only matches NameErrors raised by uncaught throws" do
@matcher.matches?(lambda{ sym }).should be_false
View
12 spec/spec_helper.rb
@@ -49,5 +49,17 @@ def fail_with(message)
config.include RSpec::Mocks::Methods
config.color_enabled = true
config.filter_run :focused => true
+
+ config.filter_run_excluding :ruby => lambda {|version|
+ case version.to_s
+ when "!jruby"
+ RUBY_ENGINE != "jruby"
+ when /^> (.*)/
+ !(RUBY_VERSION.to_s > $1)
+ else
+ !(RUBY_VERSION.to_s =~ /^#{version.to_s}/)
+ end
+ }
+
config.run_all_when_everything_filtered = true
end

No commit comments for this range

Something went wrong with that request. Please try again.