Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix `expect { ... }.to` so that it has no dependency on rspec-core an…

…d can work outside of it.
  • Loading branch information...
commit d3a6981df141667b1de752e703e00206a5f04390 1 parent 9fca9ea
@myronmarston myronmarston authored dchelimsky committed
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
20 lib/rspec/expectations/extensions/rspec/core/example_group.rb
@@ -1,20 +0,0 @@
-# TODO - as/is this forces a dependency on RSpec::Core - need to eliminate that
-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
1  lib/rspec/matchers.rb
@@ -178,6 +178,7 @@ module Matchers
require 'rspec/matchers/be_instance_of'
require 'rspec/matchers/be_kind_of'
require 'rspec/matchers/be_within'
+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
+
Please sign in to comment.
Something went wrong with that request. Please try again.