rspec-expectations 2.14.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (143) hide show
  1. checksums.yaml +15 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data/Changelog.md +369 -25
  4. data/License.txt +1 -0
  5. data/README.md +88 -15
  6. data/lib/rspec/{matchers → expectations}/configuration.rb +44 -14
  7. data/lib/rspec/expectations/expectation_target.rb +67 -33
  8. data/lib/rspec/expectations/fail_with.rb +11 -53
  9. data/lib/rspec/expectations/handler.rb +126 -31
  10. data/lib/rspec/expectations/minitest_integration.rb +16 -0
  11. data/lib/rspec/expectations/syntax.rb +60 -94
  12. data/lib/rspec/expectations/version.rb +1 -1
  13. data/lib/rspec/expectations.rb +45 -23
  14. data/lib/rspec/matchers/aliased_matcher.rb +41 -0
  15. data/lib/rspec/matchers/built_in/all.rb +78 -0
  16. data/lib/rspec/matchers/built_in/base_matcher.rb +63 -15
  17. data/lib/rspec/matchers/built_in/be.rb +170 -81
  18. data/lib/rspec/matchers/built_in/be_between.rb +77 -0
  19. data/lib/rspec/matchers/built_in/be_instance_of.rb +11 -3
  20. data/lib/rspec/matchers/built_in/be_kind_of.rb +5 -0
  21. data/lib/rspec/matchers/built_in/be_within.rb +39 -15
  22. data/lib/rspec/matchers/built_in/change.rb +273 -80
  23. data/lib/rspec/matchers/built_in/compound.rb +122 -0
  24. data/lib/rspec/matchers/built_in/contain_exactly.rb +256 -0
  25. data/lib/rspec/matchers/built_in/cover.rb +3 -0
  26. data/lib/rspec/matchers/built_in/eq.rb +60 -6
  27. data/lib/rspec/matchers/built_in/eql.rb +17 -5
  28. data/lib/rspec/matchers/built_in/equal.rb +55 -21
  29. data/lib/rspec/matchers/built_in/exist.rb +74 -10
  30. data/lib/rspec/matchers/built_in/has.rb +71 -15
  31. data/lib/rspec/matchers/built_in/include.rb +64 -27
  32. data/lib/rspec/matchers/built_in/match.rb +19 -1
  33. data/lib/rspec/matchers/built_in/operators.rb +119 -0
  34. data/lib/rspec/matchers/built_in/output.rb +150 -0
  35. data/lib/rspec/matchers/built_in/raise_error.rb +84 -42
  36. data/lib/rspec/matchers/built_in/respond_to.rb +42 -20
  37. data/lib/rspec/matchers/built_in/satisfy.rb +19 -3
  38. data/lib/rspec/matchers/built_in/start_and_end_with.rb +54 -18
  39. data/lib/rspec/matchers/built_in/throw_symbol.rb +38 -8
  40. data/lib/rspec/matchers/built_in/yield.rb +175 -68
  41. data/lib/rspec/matchers/built_in.rb +45 -33
  42. data/lib/rspec/matchers/composable.rb +179 -0
  43. data/lib/rspec/matchers/dsl.rb +362 -5
  44. data/lib/rspec/matchers/generated_descriptions.rb +13 -6
  45. data/lib/rspec/matchers/matcher_delegator.rb +37 -0
  46. data/lib/rspec/matchers/pretty.rb +27 -20
  47. data/lib/rspec/matchers.rb +361 -136
  48. data.tar.gz.sig +1 -0
  49. metadata +99 -215
  50. metadata.gz.sig +0 -0
  51. data/features/README.md +0 -48
  52. data/features/Upgrade.md +0 -53
  53. data/features/built_in_matchers/README.md +0 -90
  54. data/features/built_in_matchers/be.feature +0 -175
  55. data/features/built_in_matchers/be_within.feature +0 -48
  56. data/features/built_in_matchers/cover.feature +0 -47
  57. data/features/built_in_matchers/end_with.feature +0 -48
  58. data/features/built_in_matchers/equality.feature +0 -139
  59. data/features/built_in_matchers/exist.feature +0 -45
  60. data/features/built_in_matchers/expect_change.feature +0 -59
  61. data/features/built_in_matchers/expect_error.feature +0 -144
  62. data/features/built_in_matchers/have.feature +0 -109
  63. data/features/built_in_matchers/include.feature +0 -174
  64. data/features/built_in_matchers/match.feature +0 -52
  65. data/features/built_in_matchers/operators.feature +0 -227
  66. data/features/built_in_matchers/predicates.feature +0 -137
  67. data/features/built_in_matchers/respond_to.feature +0 -84
  68. data/features/built_in_matchers/satisfy.feature +0 -33
  69. data/features/built_in_matchers/start_with.feature +0 -48
  70. data/features/built_in_matchers/throw_symbol.feature +0 -91
  71. data/features/built_in_matchers/types.feature +0 -116
  72. data/features/built_in_matchers/yield.feature +0 -161
  73. data/features/custom_matchers/access_running_example.feature +0 -53
  74. data/features/custom_matchers/define_diffable_matcher.feature +0 -27
  75. data/features/custom_matchers/define_matcher.feature +0 -368
  76. data/features/custom_matchers/define_matcher_outside_rspec.feature +0 -38
  77. data/features/custom_matchers/define_matcher_with_fluent_interface.feature +0 -24
  78. data/features/customized_message.feature +0 -22
  79. data/features/diffing.feature +0 -85
  80. data/features/implicit_docstrings.feature +0 -52
  81. data/features/step_definitions/additional_cli_steps.rb +0 -22
  82. data/features/support/env.rb +0 -14
  83. data/features/syntax_configuration.feature +0 -71
  84. data/features/test_frameworks/test_unit.feature +0 -44
  85. data/lib/rspec/expectations/deprecation.rb +0 -17
  86. data/lib/rspec/expectations/differ.rb +0 -133
  87. data/lib/rspec/expectations/errors.rb +0 -9
  88. data/lib/rspec/expectations/extensions/array.rb +0 -9
  89. data/lib/rspec/expectations/extensions/object.rb +0 -29
  90. data/lib/rspec/expectations/extensions.rb +0 -2
  91. data/lib/rspec/matchers/be_close.rb +0 -9
  92. data/lib/rspec/matchers/built_in/have.rb +0 -124
  93. data/lib/rspec/matchers/built_in/match_array.rb +0 -51
  94. data/lib/rspec/matchers/compatibility.rb +0 -14
  95. data/lib/rspec/matchers/extensions/instance_eval_with_args.rb +0 -39
  96. data/lib/rspec/matchers/matcher.rb +0 -300
  97. data/lib/rspec/matchers/method_missing.rb +0 -12
  98. data/lib/rspec/matchers/operator_matcher.rb +0 -109
  99. data/lib/rspec/matchers/test_unit_integration.rb +0 -11
  100. data/lib/rspec-expectations.rb +0 -1
  101. data/spec/rspec/expectations/differ_spec.rb +0 -192
  102. data/spec/rspec/expectations/expectation_target_spec.rb +0 -82
  103. data/spec/rspec/expectations/extensions/kernel_spec.rb +0 -67
  104. data/spec/rspec/expectations/fail_with_spec.rb +0 -114
  105. data/spec/rspec/expectations/handler_spec.rb +0 -227
  106. data/spec/rspec/expectations/syntax_spec.rb +0 -139
  107. data/spec/rspec/matchers/base_matcher_spec.rb +0 -62
  108. data/spec/rspec/matchers/be_close_spec.rb +0 -22
  109. data/spec/rspec/matchers/be_instance_of_spec.rb +0 -63
  110. data/spec/rspec/matchers/be_kind_of_spec.rb +0 -41
  111. data/spec/rspec/matchers/be_spec.rb +0 -516
  112. data/spec/rspec/matchers/be_within_spec.rb +0 -137
  113. data/spec/rspec/matchers/change_spec.rb +0 -553
  114. data/spec/rspec/matchers/configuration_spec.rb +0 -206
  115. data/spec/rspec/matchers/cover_spec.rb +0 -69
  116. data/spec/rspec/matchers/description_generation_spec.rb +0 -190
  117. data/spec/rspec/matchers/dsl_spec.rb +0 -57
  118. data/spec/rspec/matchers/eq_spec.rb +0 -60
  119. data/spec/rspec/matchers/eql_spec.rb +0 -41
  120. data/spec/rspec/matchers/equal_spec.rb +0 -78
  121. data/spec/rspec/matchers/exist_spec.rb +0 -124
  122. data/spec/rspec/matchers/has_spec.rb +0 -122
  123. data/spec/rspec/matchers/have_spec.rb +0 -455
  124. data/spec/rspec/matchers/include_matcher_integration_spec.rb +0 -30
  125. data/spec/rspec/matchers/include_spec.rb +0 -531
  126. data/spec/rspec/matchers/match_array_spec.rb +0 -194
  127. data/spec/rspec/matchers/match_spec.rb +0 -61
  128. data/spec/rspec/matchers/matcher_spec.rb +0 -471
  129. data/spec/rspec/matchers/matchers_spec.rb +0 -37
  130. data/spec/rspec/matchers/method_missing_spec.rb +0 -28
  131. data/spec/rspec/matchers/operator_matcher_spec.rb +0 -223
  132. data/spec/rspec/matchers/raise_error_spec.rb +0 -485
  133. data/spec/rspec/matchers/respond_to_spec.rb +0 -292
  134. data/spec/rspec/matchers/satisfy_spec.rb +0 -44
  135. data/spec/rspec/matchers/start_with_end_with_spec.rb +0 -186
  136. data/spec/rspec/matchers/throw_symbol_spec.rb +0 -116
  137. data/spec/rspec/matchers/yield_spec.rb +0 -514
  138. data/spec/spec_helper.rb +0 -54
  139. data/spec/support/classes.rb +0 -56
  140. data/spec/support/in_sub_process.rb +0 -38
  141. data/spec/support/matchers.rb +0 -22
  142. data/spec/support/ruby_version.rb +0 -10
  143. data/spec/support/shared_examples.rb +0 -13
@@ -1,44 +0,0 @@
1
- Feature: Test::Unit integration
2
-
3
- RSpec-expectations is a stand-alone gem that can be used without the rest of
4
- RSpec. If you like the way Test::Unit (or MiniTest) organizes tests, but
5
- prefer RSpec's approach to expressing expectations, you can have both.
6
-
7
- The one downside is that failures are reported as errors with MiniTest.
8
-
9
- Scenario: use rspec/expectations with Test::Unit
10
- Given a file named "rspec_expectations_test.rb" with:
11
- """ruby
12
- require 'test/unit'
13
- require 'rspec/expectations'
14
-
15
- class RSpecExpectationsTest < Test::Unit::TestCase
16
- RSpec::Matchers.define :be_an_integer do
17
- match { |actual| Integer === actual }
18
- end
19
-
20
- def be_an_int
21
- # This is actually an internal rspec-expectations API, but is used
22
- # here to demonstrate that deprecation warnings from within
23
- # rspec-expectations work correcty without depending on rspec-core
24
- RSpec.deprecate(:be_an_int, :replacement => :be_an_integer)
25
- be_an_integer
26
- end
27
-
28
- def test_passing_expectation
29
- expect(1 + 3).to eq 4
30
- end
31
-
32
- def test_failing_expectation
33
- expect([1,2]).to be_empty
34
- end
35
-
36
- def test_custom_matcher_with_deprecation_warning
37
- expect(1).to be_an_int
38
- end
39
- end
40
- """
41
- When I run `ruby rspec_expectations_test.rb`
42
- Then the output should contain "3 tests, 0 assertions, 0 failures, 1 errors" or "3 tests, 0 assertions, 1 failures, 0 errors"
43
- And the output should contain "expected empty? to return true, got false"
44
- And the output should contain "be_an_int is deprecated"
@@ -1,17 +0,0 @@
1
- module RSpec
2
- module Expectations
3
- module Deprecation
4
- # @private
5
- #
6
- # Used internally to print deprecation warnings
7
- def deprecate(deprecated, options={})
8
- message = "DEPRECATION: #{deprecated} is deprecated."
9
- message << " Use #{options[:replacement]} instead." if options[:replacement]
10
- message << " Called from #{caller(0)[2]}."
11
- warn message
12
- end
13
- end
14
- end
15
-
16
- extend(Expectations::Deprecation) unless respond_to?(:deprecate)
17
- end
@@ -1,133 +0,0 @@
1
- require 'diff/lcs'
2
- require 'diff/lcs/hunk'
3
- require 'pp'
4
-
5
- module RSpec
6
- module Expectations
7
- class Differ
8
- # This is snagged from diff/lcs/ldiff.rb (which is a commandline tool)
9
- def diff_as_string(input_data_new, input_data_old)
10
- output = matching_encoding("", input_data_old)
11
- data_old = input_data_old.split(matching_encoding("\n", input_data_old)).map! { |e| e.chomp }
12
- data_new = input_data_new.split(matching_encoding("\n", input_data_new)).map! { |e| e.chomp }
13
- diffs = Diff::LCS.diff(data_old, data_new)
14
- return output if diffs.empty?
15
- oldhunk = hunk = nil
16
- file_length_difference = 0
17
- diffs.each do |piece|
18
- begin
19
- hunk = Diff::LCS::Hunk.new(
20
- data_old, data_new, piece, context_lines, file_length_difference
21
- )
22
- file_length_difference = hunk.file_length_difference
23
- next unless oldhunk
24
- # Hunks may overlap, which is why we need to be careful when our
25
- # diff includes lines of context. Otherwise, we might print
26
- # redundant lines.
27
- if (context_lines > 0) and hunk.overlaps?(oldhunk)
28
- if hunk.respond_to?(:merge)
29
- # diff-lcs 1.2.x
30
- hunk.merge(oldhunk)
31
- else
32
- # diff-lcs 1.1.3
33
- hunk.unshift(oldhunk)
34
- end
35
- else
36
- output << matching_encoding(oldhunk.diff(format).to_s, output)
37
- end
38
- ensure
39
- oldhunk = hunk
40
- output << matching_encoding("\n", output)
41
- end
42
- end
43
- #Handle the last remaining hunk
44
- output << matching_encoding(oldhunk.diff(format).to_s,output)
45
- output << matching_encoding("\n",output)
46
- color_diff output
47
- rescue Encoding::CompatibilityError
48
- if input_data_new.encoding != input_data_old.encoding
49
- "Could not produce a diff because the encoding of the actual string (#{input_data_old.encoding}) "+
50
- "differs from the encoding of the expected string (#{input_data_new.encoding})"
51
- else
52
- "Could not produce a diff because of the encoding of the string (#{input_data_old.encoding})"
53
- end
54
- end
55
-
56
- def diff_as_object(actual, expected)
57
- actual_as_string = object_to_string(actual)
58
- expected_as_string = object_to_string(expected)
59
- if diff = diff_as_string(actual_as_string, expected_as_string)
60
- color_diff diff
61
- end
62
- end
63
-
64
- protected
65
-
66
- def format
67
- :unified
68
- end
69
-
70
- def context_lines
71
- 3
72
- end
73
-
74
- def color(text, color_code)
75
- "\e[#{color_code}m#{text}\e[0m"
76
- end
77
-
78
- def red(text)
79
- color(text, 31)
80
- end
81
-
82
- def green(text)
83
- color(text, 32)
84
- end
85
-
86
- def blue(text)
87
- color(text, 34)
88
- end
89
-
90
- def color_diff(diff)
91
- return diff unless RSpec::Matchers.configuration.color?
92
-
93
- diff.lines.map { |line|
94
- case line[0].chr
95
- when "+"
96
- green line
97
- when "-"
98
- red line
99
- when "@"
100
- line[1].chr == "@" ? blue(line) : line
101
- else
102
- line
103
- end
104
- }.join
105
- end
106
-
107
- def object_to_string(object)
108
- case object
109
- when Hash
110
- object.keys.sort_by { |k| k.to_s }.map do |k|
111
- %(#{PP.singleline_pp(k, "")} => #{PP.singleline_pp(object[k], "")})
112
- end.join(",\n")
113
- when String
114
- object =~ /\n/ ? object : object.inspect
115
- else
116
- PP.pp(object,"")
117
- end
118
- end
119
-
120
- if String.method_defined?(:encoding)
121
- def matching_encoding(string, source)
122
- string.encode(source.encoding)
123
- end
124
- else
125
- def matching_encoding(string, source)
126
- string
127
- end
128
- end
129
- end
130
-
131
- end
132
- end
133
-
@@ -1,9 +0,0 @@
1
- module RSpec
2
- module Expectations
3
- if defined?(Test::Unit::AssertionFailedError)
4
- class ExpectationNotMetError < Test::Unit::AssertionFailedError; end
5
- else
6
- class ExpectationNotMetError < ::StandardError; end
7
- end
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- # @private
2
- class Array
3
- unless public_instance_methods.map {|m| m.to_s}.include?('none?')
4
- # Supports +none?+ on early patch levels of Ruby 1.8.6
5
- def none?(&block)
6
- !any?(&block)
7
- end
8
- end
9
- end
@@ -1,29 +0,0 @@
1
- module RSpec
2
- module Expectations
3
- module DeprecatedConstants
4
- # Displays deprecation warning when it captures Rspec and Spec. Otherwise
5
- # delegates to super.
6
- def const_missing(name)
7
- case name
8
- when :Rspec, :Spec
9
- RSpec.deprecate(name.to_s, :replacement => "RSpec")
10
- RSpec
11
- else
12
- begin
13
- super
14
- rescue Exception => e
15
- e.backtrace.reject! {|l| l =~ Regexp.compile(__FILE__) }
16
- raise e
17
- end
18
- end
19
- end
20
- end
21
-
22
- # @deprecated (no replacement)
23
- def differ=(ignore)
24
- RSpec.deprecate("RSpec::Expectations.differ=(differ)")
25
- end
26
- end
27
- end
28
-
29
- extend RSpec::Expectations::DeprecatedConstants
@@ -1,2 +0,0 @@
1
- require 'rspec/expectations/extensions/array'
2
- require 'rspec/expectations/extensions/object'
@@ -1,9 +0,0 @@
1
- module RSpec
2
- module Matchers
3
- # @deprecated use +be_within+ instead.
4
- def be_close(expected, delta)
5
- RSpec.deprecate("be_close(#{expected}, #{delta})", :replacement => "be_within(#{delta}).of(#{expected})")
6
- be_within(delta).of(expected)
7
- end
8
- end
9
- end
@@ -1,124 +0,0 @@
1
- module RSpec
2
- module Matchers
3
- module BuiltIn
4
- class Have
5
- QUERY_METHODS = [:size, :length, :count].freeze
6
-
7
- def initialize(expected, relativity=:exactly)
8
- @expected = case expected
9
- when :no then 0
10
- when String then expected.to_i
11
- else expected
12
- end
13
- @relativity = relativity
14
- @actual = @collection_name = @plural_collection_name = nil
15
- end
16
-
17
- def relativities
18
- @relativities ||= {
19
- :exactly => "",
20
- :at_least => "at least ",
21
- :at_most => "at most "
22
- }
23
- end
24
-
25
- def matches?(collection_or_owner)
26
- collection = determine_collection(collection_or_owner)
27
- case collection
28
- when enumerator_class
29
- for query_method in QUERY_METHODS
30
- next unless collection.respond_to?(query_method)
31
- @actual = collection.__send__(query_method)
32
- break unless @actual.nil?
33
- end
34
- raise not_a_collection if @actual.nil?
35
- else
36
- query_method = determine_query_method(collection)
37
- raise not_a_collection unless query_method
38
- @actual = collection.__send__(query_method)
39
- end
40
- case @relativity
41
- when :at_least then @actual >= @expected
42
- when :at_most then @actual <= @expected
43
- else @actual == @expected
44
- end
45
- end
46
- alias == matches?
47
-
48
- def determine_collection(collection_or_owner)
49
- if collection_or_owner.respond_to?(@collection_name)
50
- collection_or_owner.__send__(@collection_name, *@args, &@block)
51
- elsif (@plural_collection_name && collection_or_owner.respond_to?(@plural_collection_name))
52
- collection_or_owner.__send__(@plural_collection_name, *@args, &@block)
53
- elsif determine_query_method(collection_or_owner)
54
- collection_or_owner
55
- else
56
- collection_or_owner.__send__(@collection_name, *@args, &@block)
57
- end
58
- end
59
-
60
- def determine_query_method(collection)
61
- QUERY_METHODS.detect {|m| collection.respond_to?(m)}
62
- end
63
-
64
- def not_a_collection
65
- "expected #{@collection_name} to be a collection but it does not respond to #length, #size or #count"
66
- end
67
-
68
- def failure_message_for_should
69
- "expected #{relative_expectation} #{@collection_name}, got #{@actual}"
70
- end
71
-
72
- def failure_message_for_should_not
73
- if @relativity == :exactly
74
- return "expected target not to have #{@expected} #{@collection_name}, got #{@actual}"
75
- elsif @relativity == :at_most
76
- return <<-EOF
77
- Isn't life confusing enough?
78
- Instead of having to figure out the meaning of this:
79
- #{Expectations::Syntax.negative_expression("actual", "have_at_most(#{@expected}).#{@collection_name}")}
80
- We recommend that you use this instead:
81
- #{Expectations::Syntax.positive_expression("actual", "have_at_least(#{@expected + 1}).#{@collection_name}")}
82
- EOF
83
- elsif @relativity == :at_least
84
- return <<-EOF
85
- Isn't life confusing enough?
86
- Instead of having to figure out the meaning of this:
87
- #{Expectations::Syntax.negative_expression("actual", "have_at_least(#{@expected}).#{@collection_name}")}
88
- We recommend that you use this instead:
89
- #{Expectations::Syntax.positive_expression("actual", "have_at_most(#{@expected - 1}).#{@collection_name}")}
90
- EOF
91
- end
92
- end
93
-
94
- def description
95
- "have #{relative_expectation} #{@collection_name}"
96
- end
97
-
98
- def respond_to?(m)
99
- @expected.respond_to?(m) || super
100
- end
101
-
102
- private
103
-
104
- def method_missing(method, *args, &block)
105
- @collection_name = method
106
- if inflector = (defined?(ActiveSupport::Inflector) && ActiveSupport::Inflector.respond_to?(:pluralize) ? ActiveSupport::Inflector : (defined?(Inflector) ? Inflector : nil))
107
- @plural_collection_name = inflector.pluralize(method.to_s)
108
- end
109
- @args = args
110
- @block = block
111
- self
112
- end
113
-
114
- def relative_expectation
115
- "#{relativities[@relativity]}#{@expected}"
116
- end
117
-
118
- def enumerator_class
119
- RUBY_VERSION < '1.9' ? Enumerable::Enumerator : Enumerator
120
- end
121
- end
122
- end
123
- end
124
- end
@@ -1,51 +0,0 @@
1
- module RSpec
2
- module Matchers
3
- module BuiltIn
4
- class MatchArray < BaseMatcher
5
- def match(expected, actual)
6
- return false unless actual.respond_to? :to_ary
7
- @extra_items = difference_between_arrays(actual, expected)
8
- @missing_items = difference_between_arrays(expected, actual)
9
- @extra_items.empty? & @missing_items.empty?
10
- end
11
-
12
- def failure_message_for_should
13
- if actual.respond_to? :to_ary
14
- message = "expected collection contained: #{safe_sort(expected).inspect}\n"
15
- message += "actual collection contained: #{safe_sort(actual).inspect}\n"
16
- message += "the missing elements were: #{safe_sort(@missing_items).inspect}\n" unless @missing_items.empty?
17
- message += "the extra elements were: #{safe_sort(@extra_items).inspect}\n" unless @extra_items.empty?
18
- else
19
- message = "expected an array, actual collection was #{actual.inspect}"
20
- end
21
-
22
- message
23
- end
24
-
25
- def failure_message_for_should_not
26
- "Matcher does not support should_not"
27
- end
28
-
29
- def description
30
- "contain exactly #{_pretty_print(expected)}"
31
- end
32
-
33
- private
34
-
35
- def safe_sort(array)
36
- array.sort rescue array
37
- end
38
-
39
- def difference_between_arrays(array_1, array_2)
40
- difference = array_1.to_ary.dup
41
- array_2.to_ary.each do |element|
42
- if index = difference.index(element)
43
- difference.delete_at(index)
44
- end
45
- end
46
- difference
47
- end
48
- end
49
- end
50
- end
51
- end
@@ -1,14 +0,0 @@
1
- RSpec::Matchers.constants.each do |c|
2
- if Class === (klass = RSpec::Matchers.const_get(c))
3
- if klass.public_instance_methods.any? {|m| ['failure_message_for_should',:failure_message_for_should].include?(m)}
4
- klass.class_eval do
5
- alias_method :failure_message, :failure_message_for_should
6
- end
7
- end
8
- if klass.public_instance_methods.any? {|m| ['failure_message_for_should_not',:failure_message_for_should_not].include?(m)}
9
- klass.class_eval do
10
- alias_method :negative_failure_message, :failure_message_for_should_not
11
- end
12
- end
13
- end
14
- end
@@ -1,39 +0,0 @@
1
- module RSpec
2
- module Matchers
3
- module Extensions
4
- module InstanceEvalWithArgs
5
- # based on Bounded Spec InstanceExec (Mauricio Fernandez)
6
- # http://eigenclass.org/hiki/bounded+space+instance_exec
7
- # - uses singleton_class instead of global InstanceExecHelper module
8
- # - this keeps it scoped to classes/modules that include this module
9
- # - only necessary for ruby 1.8.6
10
- def instance_eval_with_args(*args, &block)
11
- return instance_exec(*args, &block) if respond_to?(:instance_exec)
12
-
13
- # If there are no args and the block doesn't expect any, there's no
14
- # need to fake instance_exec with our hack below.
15
- # Notes:
16
- # * lambda { }.arity # => -1
17
- # * lambda { || }.arity # => 0
18
- # * lambda { |*a| }.arity # -1
19
- return instance_eval(&block) if block.arity < 1 && args.empty?
20
-
21
- singleton_class = (class << self; self; end)
22
- begin
23
- orig_critical, Thread.critical = Thread.critical, true
24
- n = 0
25
- n += 1 while respond_to?(method_name="__instance_exec#{n}")
26
- singleton_class.module_eval{ define_method(method_name, &block) }
27
- ensure
28
- Thread.critical = orig_critical
29
- end
30
- begin
31
- return __send__(method_name, *args)
32
- ensure
33
- singleton_class.module_eval{ remove_method(method_name) } rescue nil
34
- end
35
- end
36
- end
37
- end
38
- end
39
- end