rspec-expectations 2.11.3 → 3.11.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 (152) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data/.document +1 -1
  4. data/.yardopts +1 -1
  5. data/Changelog.md +1026 -21
  6. data/{License.txt → LICENSE.md} +5 -3
  7. data/README.md +174 -78
  8. data/lib/rspec/expectations/block_snippet_extractor.rb +253 -0
  9. data/lib/rspec/expectations/configuration.rb +230 -0
  10. data/lib/rspec/expectations/expectation_target.rb +130 -55
  11. data/lib/rspec/expectations/fail_with.rb +17 -33
  12. data/lib/rspec/expectations/failure_aggregator.rb +212 -0
  13. data/lib/rspec/expectations/handler.rb +163 -29
  14. data/lib/rspec/expectations/minitest_integration.rb +58 -0
  15. data/lib/rspec/expectations/syntax.rb +68 -54
  16. data/lib/rspec/expectations/version.rb +1 -1
  17. data/lib/rspec/expectations.rb +59 -24
  18. data/lib/rspec/matchers/aliased_matcher.rb +116 -0
  19. data/lib/rspec/matchers/built_in/all.rb +86 -0
  20. data/lib/rspec/matchers/built_in/base_matcher.rb +150 -20
  21. data/lib/rspec/matchers/built_in/be.rb +115 -109
  22. data/lib/rspec/matchers/built_in/be_between.rb +77 -0
  23. data/lib/rspec/matchers/built_in/be_instance_of.rb +16 -1
  24. data/lib/rspec/matchers/built_in/be_kind_of.rb +10 -1
  25. data/lib/rspec/matchers/built_in/be_within.rb +43 -17
  26. data/lib/rspec/matchers/built_in/change.rb +392 -75
  27. data/lib/rspec/matchers/built_in/compound.rb +290 -0
  28. data/lib/rspec/matchers/built_in/contain_exactly.rb +302 -0
  29. data/lib/rspec/matchers/built_in/count_expectation.rb +169 -0
  30. data/lib/rspec/matchers/built_in/cover.rb +3 -0
  31. data/lib/rspec/matchers/built_in/eq.rb +26 -8
  32. data/lib/rspec/matchers/built_in/eql.rb +19 -8
  33. data/lib/rspec/matchers/built_in/equal.rb +56 -19
  34. data/lib/rspec/matchers/built_in/exist.rb +74 -10
  35. data/lib/rspec/matchers/built_in/has.rb +141 -22
  36. data/lib/rspec/matchers/built_in/have_attributes.rb +114 -0
  37. data/lib/rspec/matchers/built_in/include.rb +175 -20
  38. data/lib/rspec/matchers/built_in/match.rb +95 -1
  39. data/lib/rspec/matchers/built_in/operators.rb +128 -0
  40. data/lib/rspec/matchers/built_in/output.rb +207 -0
  41. data/lib/rspec/matchers/built_in/raise_error.rb +212 -38
  42. data/lib/rspec/matchers/built_in/respond_to.rb +155 -29
  43. data/lib/rspec/matchers/built_in/satisfy.rb +39 -9
  44. data/lib/rspec/matchers/built_in/start_or_end_with.rb +94 -0
  45. data/lib/rspec/matchers/built_in/throw_symbol.rb +58 -14
  46. data/lib/rspec/matchers/built_in/yield.rb +252 -98
  47. data/lib/rspec/matchers/built_in.rb +47 -33
  48. data/lib/rspec/matchers/composable.rb +171 -0
  49. data/lib/rspec/matchers/dsl.rb +530 -10
  50. data/lib/rspec/matchers/english_phrasing.rb +58 -0
  51. data/lib/rspec/matchers/expecteds_for_multiple_diffs.rb +82 -0
  52. data/lib/rspec/matchers/fail_matchers.rb +42 -0
  53. data/lib/rspec/matchers/generated_descriptions.rb +15 -10
  54. data/lib/rspec/matchers/matcher_delegator.rb +35 -0
  55. data/lib/rspec/matchers/matcher_protocol.rb +105 -0
  56. data/lib/rspec/matchers.rb +604 -252
  57. data.tar.gz.sig +0 -0
  58. metadata +178 -278
  59. metadata.gz.sig +0 -0
  60. data/features/README.md +0 -49
  61. data/features/Upgrade.md +0 -53
  62. data/features/built_in_matchers/README.md +0 -90
  63. data/features/built_in_matchers/be.feature +0 -173
  64. data/features/built_in_matchers/be_within.feature +0 -46
  65. data/features/built_in_matchers/cover.feature +0 -45
  66. data/features/built_in_matchers/end_with.feature +0 -46
  67. data/features/built_in_matchers/equality.feature +0 -145
  68. data/features/built_in_matchers/exist.feature +0 -43
  69. data/features/built_in_matchers/expect_change.feature +0 -59
  70. data/features/built_in_matchers/expect_error.feature +0 -138
  71. data/features/built_in_matchers/have.feature +0 -103
  72. data/features/built_in_matchers/include.feature +0 -121
  73. data/features/built_in_matchers/match.feature +0 -50
  74. data/features/built_in_matchers/operators.feature +0 -221
  75. data/features/built_in_matchers/predicates.feature +0 -128
  76. data/features/built_in_matchers/respond_to.feature +0 -78
  77. data/features/built_in_matchers/satisfy.feature +0 -31
  78. data/features/built_in_matchers/start_with.feature +0 -46
  79. data/features/built_in_matchers/throw_symbol.feature +0 -85
  80. data/features/built_in_matchers/types.feature +0 -114
  81. data/features/built_in_matchers/yield.feature +0 -146
  82. data/features/custom_matchers/access_running_example.feature +0 -53
  83. data/features/custom_matchers/define_diffable_matcher.feature +0 -27
  84. data/features/custom_matchers/define_matcher.feature +0 -340
  85. data/features/custom_matchers/define_matcher_outside_rspec.feature +0 -38
  86. data/features/custom_matchers/define_matcher_with_fluent_interface.feature +0 -24
  87. data/features/customized_message.feature +0 -22
  88. data/features/diffing.feature +0 -85
  89. data/features/implicit_docstrings.feature +0 -52
  90. data/features/step_definitions/additional_cli_steps.rb +0 -22
  91. data/features/support/env.rb +0 -5
  92. data/features/syntax_configuration.feature +0 -68
  93. data/features/test_frameworks/test_unit.feature +0 -46
  94. data/lib/rspec/expectations/deprecation.rb +0 -38
  95. data/lib/rspec/expectations/differ.rb +0 -81
  96. data/lib/rspec/expectations/errors.rb +0 -9
  97. data/lib/rspec/expectations/extensions/array.rb +0 -9
  98. data/lib/rspec/expectations/extensions/object.rb +0 -39
  99. data/lib/rspec/expectations/extensions.rb +0 -2
  100. data/lib/rspec/matchers/be_close.rb +0 -9
  101. data/lib/rspec/matchers/built_in/have.rb +0 -108
  102. data/lib/rspec/matchers/built_in/match_array.rb +0 -45
  103. data/lib/rspec/matchers/built_in/start_and_end_with.rb +0 -48
  104. data/lib/rspec/matchers/compatibility.rb +0 -14
  105. data/lib/rspec/matchers/configuration.rb +0 -66
  106. data/lib/rspec/matchers/extensions/instance_eval_with_args.rb +0 -39
  107. data/lib/rspec/matchers/matcher.rb +0 -299
  108. data/lib/rspec/matchers/method_missing.rb +0 -12
  109. data/lib/rspec/matchers/operator_matcher.rb +0 -84
  110. data/lib/rspec/matchers/pretty.rb +0 -60
  111. data/lib/rspec-expectations.rb +0 -1
  112. data/spec/rspec/expectations/differ_spec.rb +0 -153
  113. data/spec/rspec/expectations/expectation_target_spec.rb +0 -65
  114. data/spec/rspec/expectations/extensions/kernel_spec.rb +0 -67
  115. data/spec/rspec/expectations/fail_with_spec.rb +0 -70
  116. data/spec/rspec/expectations/handler_spec.rb +0 -206
  117. data/spec/rspec/matchers/base_matcher_spec.rb +0 -60
  118. data/spec/rspec/matchers/be_close_spec.rb +0 -22
  119. data/spec/rspec/matchers/be_instance_of_spec.rb +0 -40
  120. data/spec/rspec/matchers/be_kind_of_spec.rb +0 -37
  121. data/spec/rspec/matchers/be_spec.rb +0 -452
  122. data/spec/rspec/matchers/be_within_spec.rb +0 -80
  123. data/spec/rspec/matchers/change_spec.rb +0 -528
  124. data/spec/rspec/matchers/configuration_spec.rb +0 -202
  125. data/spec/rspec/matchers/cover_spec.rb +0 -69
  126. data/spec/rspec/matchers/description_generation_spec.rb +0 -176
  127. data/spec/rspec/matchers/dsl_spec.rb +0 -57
  128. data/spec/rspec/matchers/eq_spec.rb +0 -54
  129. data/spec/rspec/matchers/eql_spec.rb +0 -41
  130. data/spec/rspec/matchers/equal_spec.rb +0 -60
  131. data/spec/rspec/matchers/exist_spec.rb +0 -110
  132. data/spec/rspec/matchers/has_spec.rb +0 -118
  133. data/spec/rspec/matchers/have_spec.rb +0 -461
  134. data/spec/rspec/matchers/include_spec.rb +0 -367
  135. data/spec/rspec/matchers/match_array_spec.rb +0 -124
  136. data/spec/rspec/matchers/match_spec.rb +0 -61
  137. data/spec/rspec/matchers/matcher_spec.rb +0 -434
  138. data/spec/rspec/matchers/matchers_spec.rb +0 -31
  139. data/spec/rspec/matchers/method_missing_spec.rb +0 -24
  140. data/spec/rspec/matchers/operator_matcher_spec.rb +0 -221
  141. data/spec/rspec/matchers/raise_error_spec.rb +0 -344
  142. data/spec/rspec/matchers/respond_to_spec.rb +0 -295
  143. data/spec/rspec/matchers/satisfy_spec.rb +0 -44
  144. data/spec/rspec/matchers/start_with_end_with_spec.rb +0 -182
  145. data/spec/rspec/matchers/throw_symbol_spec.rb +0 -116
  146. data/spec/rspec/matchers/yield_spec.rb +0 -402
  147. data/spec/spec_helper.rb +0 -27
  148. data/spec/support/classes.rb +0 -56
  149. data/spec/support/in_sub_process.rb +0 -31
  150. data/spec/support/matchers.rb +0 -22
  151. data/spec/support/ruby_version.rb +0 -10
  152. data/spec/support/shared_examples.rb +0 -13
@@ -1,46 +0,0 @@
1
- Feature: Test::Unit integration
2
-
3
- RSpec-expectations is a stand-alone gem that can be used without
4
- the rest of RSpec. It can easily be used with another test
5
- framework such as Test::Unit if you like RSpec's should/should_not
6
- syntax but prefer the test organization of another framework.
7
-
8
- Scenario: Basic Test::Unit usage
9
- Given a file named "rspec_expectations_test.rb" with:
10
- """
11
- require 'test/unit'
12
- require 'rspec/expectations'
13
-
14
- class RSpecExpectationsTest < Test::Unit::TestCase
15
- RSpec::Matchers.define :be_an_integer do
16
- match { |actual| Integer === actual }
17
- end
18
-
19
- def be_an_int
20
- RSpec.deprecate(:be_an_int, :be_an_integer)
21
- be_an_integer
22
- end
23
-
24
- def test_passing_expectation
25
- x = 1 + 3
26
- x.should == 4
27
- end
28
-
29
- def test_failing_expectation
30
- array = [1, 2]
31
- array.should be_empty
32
- end
33
-
34
- def test_expect_matcher
35
- expect { @a = 5 }.to change { @a }.from(nil).to(5)
36
- end
37
-
38
- def test_custom_matcher_and_deprecation_warning
39
- 1.should be_an_int
40
- end
41
- end
42
- """
43
- When I run `ruby rspec_expectations_test.rb`
44
- Then the output should contain "4 tests, 0 assertions, 1 failures, 0 errors" or "4 tests, 0 assertions, 0 failures, 1 errors"
45
- And the output should contain "expected empty? to return true, got false"
46
- And the output should contain "be_an_int is deprecated"
@@ -1,38 +0,0 @@
1
- module RSpec
2
- unless respond_to?(:deprecate)
3
- class << self
4
- # Used internally by RSpec to display standard deprecation warnings.
5
- # This is also defined in rspec-core, but we can't assume it's loaded
6
- # since rspec-expectations should be usable w/o rspec-core.
7
- def deprecate(method, alternate_method=nil, version=nil)
8
- version_string = version ? "rspec-#{version}" : "a future version of RSpec"
9
-
10
- message = <<-NOTICE
11
-
12
- *****************************************************************
13
- DEPRECATION WARNING: you are using deprecated behaviour that will
14
- be removed from #{version_string}.
15
-
16
- #{caller(0)[2]}
17
-
18
- * #{method} is deprecated.
19
- NOTICE
20
- if alternate_method
21
- message << <<-ADDITIONAL
22
- * please use #{alternate_method} instead.
23
- ADDITIONAL
24
- end
25
-
26
- message << "*****************************************************************"
27
- warn_deprecation(message)
28
- end
29
-
30
- # Used internally by RSpec to display custom deprecation warnings. This
31
- # is also defined in rspec-core, but we can't assume it's loaded since
32
- # rspec-expectations should be usable w/o rspec-core.
33
- def warn_deprecation(message)
34
- send :warn, message
35
- end
36
- end
37
- end
38
- end
@@ -1,81 +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(data_new, data_old)
10
- data_old = data_old.split(/\n/).map! { |e| e.chomp }
11
- data_new = data_new.split(/\n/).map! { |e| e.chomp }
12
- diffs = Diff::LCS.diff(data_old, data_new)
13
- output = ""
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
- hunk.unshift(oldhunk)
29
- else
30
- output << oldhunk.diff(format)
31
- end
32
- ensure
33
- oldhunk = hunk
34
- output << "\n"
35
- end
36
- end
37
- #Handle the last remaining hunk
38
- output << oldhunk.diff(format) << "\n"
39
- end
40
-
41
- def diff_as_object(actual, expected)
42
- actual_as_string = object_to_string(actual)
43
- expected_as_string = object_to_string(expected)
44
- diff = diff_as_string(actual_as_string, expected_as_string)
45
-
46
- if diff.empty?
47
- "#{actual}.==(#{expected}) returned false even though the diff " \
48
- "between #{actual} and #{expected} is empty. Check the " \
49
- "implementation of #{actual}.==."
50
- else
51
- diff
52
- end
53
- end
54
-
55
- protected
56
-
57
- def format
58
- :unified
59
- end
60
-
61
- def context_lines
62
- 3
63
- end
64
-
65
- def object_to_string(object)
66
- case object
67
- when Hash
68
- object.keys.sort_by { |k| k.to_s }.map do |k|
69
- %(#{PP.singleline_pp(k, "")} => #{PP.singleline_pp(object[k], "")})
70
- end.join(",\n")
71
- when String
72
- object =~ /\n/ ? object : object.inspect
73
- else
74
- PP.pp(object,"")
75
- end
76
- end
77
- end
78
-
79
- end
80
- end
81
-
@@ -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,39 +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.warn_deprecation <<-WARNING
10
- *****************************************************************
11
- DEPRECATION WARNING: you are using a deprecated constant that will
12
- be removed from a future version of RSpec.
13
-
14
- #{caller(0)[2]}
15
-
16
- * #{name} is deprecated.
17
- * RSpec is the new top-level module in RSpec-2
18
- ***************************************************************
19
- WARNING
20
- RSpec
21
- else
22
- begin
23
- super
24
- rescue Exception => e
25
- e.backtrace.reject! {|l| l =~ Regexp.compile(__FILE__) }
26
- raise e
27
- end
28
- end
29
- end
30
- end
31
-
32
- # @deprecated (no replacement)
33
- def differ=(ignore)
34
- RSpec.deprecate("RSpec::Expectations.differ=(differ)", "nothing at all (diffing is now automatic and no longer configurable)")
35
- end
36
- end
37
- end
38
-
39
- 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})", "be_within(#{delta}).of(#{expected})")
6
- be_within(delta).of(expected)
7
- end
8
- end
9
- end
@@ -1,108 +0,0 @@
1
- module RSpec
2
- module Matchers
3
- module BuiltIn
4
- class Have
5
- def initialize(expected, relativity=:exactly)
6
- @expected = case expected
7
- when :no then 0
8
- when String then expected.to_i
9
- else expected
10
- end
11
- @relativity = relativity
12
- @actual = @collection_name = @plural_collection_name = nil
13
- end
14
-
15
- def relativities
16
- @relativities ||= {
17
- :exactly => "",
18
- :at_least => "at least ",
19
- :at_most => "at most "
20
- }
21
- end
22
-
23
- def matches?(collection_or_owner)
24
- collection = determine_collection(collection_or_owner)
25
- query_method = determine_query_method(collection)
26
- raise not_a_collection unless query_method
27
- @actual = collection.send(query_method)
28
- case @relativity
29
- when :at_least then @actual >= @expected
30
- when :at_most then @actual <= @expected
31
- else @actual == @expected
32
- end
33
- end
34
- alias == matches?
35
-
36
- def determine_collection(collection_or_owner)
37
- if collection_or_owner.respond_to?(@collection_name)
38
- collection_or_owner.send(@collection_name, *@args, &@block)
39
- elsif (@plural_collection_name && collection_or_owner.respond_to?(@plural_collection_name))
40
- collection_or_owner.send(@plural_collection_name, *@args, &@block)
41
- elsif determine_query_method(collection_or_owner)
42
- collection_or_owner
43
- else
44
- collection_or_owner.send(@collection_name, *@args, &@block)
45
- end
46
- end
47
-
48
- def determine_query_method(collection)
49
- [:size, :length, :count].detect {|m| collection.respond_to?(m)}
50
- end
51
-
52
- def not_a_collection
53
- "expected #{@collection_name} to be a collection but it does not respond to #length, #size or #count"
54
- end
55
-
56
- def failure_message_for_should
57
- "expected #{relative_expectation} #{@collection_name}, got #{@actual}"
58
- end
59
-
60
- def failure_message_for_should_not
61
- if @relativity == :exactly
62
- return "expected target not to have #{@expected} #{@collection_name}, got #{@actual}"
63
- elsif @relativity == :at_most
64
- return <<-EOF
65
- Isn't life confusing enough?
66
- Instead of having to figure out the meaning of this:
67
- should_not have_at_most(#{@expected}).#{@collection_name}
68
- We recommend that you use this instead:
69
- should have_at_least(#{@expected + 1}).#{@collection_name}
70
- EOF
71
- elsif @relativity == :at_least
72
- return <<-EOF
73
- Isn't life confusing enough?
74
- Instead of having to figure out the meaning of this:
75
- should_not have_at_least(#{@expected}).#{@collection_name}
76
- We recommend that you use this instead:
77
- should have_at_most(#{@expected - 1}).#{@collection_name}
78
- EOF
79
- end
80
- end
81
-
82
- def description
83
- "have #{relative_expectation} #{@collection_name}"
84
- end
85
-
86
- def respond_to?(m)
87
- @expected.respond_to?(m) || super
88
- end
89
-
90
- private
91
-
92
- def method_missing(method, *args, &block)
93
- @collection_name = method
94
- if inflector = (defined?(ActiveSupport::Inflector) && ActiveSupport::Inflector.respond_to?(:pluralize) ? ActiveSupport::Inflector : (defined?(Inflector) ? Inflector : nil))
95
- @plural_collection_name = inflector.pluralize(method.to_s)
96
- end
97
- @args = args
98
- @block = block
99
- self
100
- end
101
-
102
- def relative_expectation
103
- "#{relativities[@relativity]}#{@expected}"
104
- end
105
- end
106
- end
107
- end
108
- end
@@ -1,45 +0,0 @@
1
- module RSpec
2
- module Matchers
3
- module BuiltIn
4
- class MatchArray < BaseMatcher
5
- def match(expected, actual)
6
- @extra_items = difference_between_arrays(actual, expected)
7
- @missing_items = difference_between_arrays(expected, actual)
8
- @extra_items.empty? & @missing_items.empty?
9
- end
10
-
11
- def failure_message_for_should
12
- message = "expected collection contained: #{safe_sort(expected).inspect}\n"
13
- message += "actual collection contained: #{safe_sort(actual).inspect}\n"
14
- message += "the missing elements were: #{safe_sort(@missing_items).inspect}\n" unless @missing_items.empty?
15
- message += "the extra elements were: #{safe_sort(@extra_items).inspect}\n" unless @extra_items.empty?
16
- message
17
- end
18
-
19
- def failure_message_for_should_not
20
- "Matcher does not support should_not"
21
- end
22
-
23
- def description
24
- "contain exactly #{_pretty_print(expected)}"
25
- end
26
-
27
- private
28
-
29
- def safe_sort(array)
30
- array.sort rescue array
31
- end
32
-
33
- def difference_between_arrays(array_1, array_2)
34
- difference = array_1.dup
35
- array_2.each do |element|
36
- if index = difference.index(element)
37
- difference.delete_at(index)
38
- end
39
- end
40
- difference
41
- end
42
- end
43
- end
44
- end
45
- end
@@ -1,48 +0,0 @@
1
- module RSpec
2
- module Matchers
3
- module BuiltIn
4
- class StartAndEndWith < BaseMatcher
5
- def initialize(*expected)
6
- @expected = expected.length == 1 ? expected.first : expected
7
- end
8
-
9
- def matches?(actual)
10
- @actual = actual.respond_to?(:[]) ? actual : (raise ArgumentError.new("#{actual.inspect} does not respond to :[]"))
11
- begin
12
- @expected.respond_to?(:length) ? subset_matches?(@expected, @actual) : element_matches?(@expected, @actual)
13
- rescue ArgumentError
14
- raise ArgumentError.new("#{actual.inspect} does not have ordered elements")
15
- end
16
- end
17
-
18
- def failure_message_for_should
19
- "expected #{@actual.inspect} to #{self.class.name.split('::').last.sub(/With/,'').downcase} with #{@expected.inspect}"
20
- end
21
-
22
- def failure_message_for_should_not
23
- "expected #{@actual.inspect} not to #{self.class.name.split('::').last.sub(/With/,'').downcase} with #{@expected.inspect}"
24
- end
25
- end
26
-
27
- class StartWith < StartAndEndWith
28
- def subset_matches?(expected, actual)
29
- actual[0, expected.length] == expected
30
- end
31
-
32
- def element_matches?(expected, actual)
33
- @actual[0] == @expected
34
- end
35
- end
36
-
37
- class EndWith < StartAndEndWith
38
- def subset_matches?(expected, actual)
39
- actual[-expected.length, expected.length] == expected
40
- end
41
-
42
- def element_matches?(expected, actual)
43
- actual[-1] == expected
44
- end
45
- end
46
- end
47
- end
48
- 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,66 +0,0 @@
1
- require 'rspec/expectations/syntax'
2
-
3
- module RSpec
4
- module Matchers
5
- # Provides configuration options for rspec-expectations.
6
- class Configuration
7
- # Configures the supported syntax.
8
- # @param [Array<Symbol>, Symbol] values the syntaxes to enable
9
- # @example
10
- # RSpec.configure do |rspec|
11
- # rspec.expect_with :rspec do |c|
12
- # c.syntax = :should
13
- # # or
14
- # c.syntax = :expect
15
- # # or
16
- # c.syntax = [:should, :expect]
17
- # end
18
- # end
19
- def syntax=(values)
20
- if Array(values).include?(:expect)
21
- Expectations::Syntax.enable_expect
22
- else
23
- Expectations::Syntax.disable_expect
24
- end
25
-
26
- if Array(values).include?(:should)
27
- Expectations::Syntax.enable_should
28
- else
29
- Expectations::Syntax.disable_should
30
- end
31
- end
32
-
33
- # The list of configured syntaxes.
34
- # @return [Array<Symbol>] the list of configured syntaxes.
35
- def syntax
36
- syntaxes = []
37
- syntaxes << :should if Expectations::Syntax.should_enabled?
38
- syntaxes << :expect if Expectations::Syntax.expect_enabled?
39
- syntaxes
40
- end
41
-
42
- # Adds `should` and `should_not` to the given classes
43
- # or modules. This can be used to ensure `should` works
44
- # properly on things like proxy objects (particular
45
- # `Delegator`-subclassed objects on 1.8).
46
- #
47
- # @param [Array<Module>] modules the list of classes or modules
48
- # to add `should` and `should_not` to.
49
- def add_should_and_should_not_to(*modules)
50
- modules.each do |mod|
51
- Expectations::Syntax.enable_should(mod)
52
- end
53
- end
54
- end
55
-
56
- # The configuration object
57
- # @return [RSpec::Matchers::Configuration] the configuration object
58
- def self.configuration
59
- @configuration ||= Configuration.new
60
- end
61
-
62
- # set default syntax
63
- configuration.syntax = [:expect, :should]
64
- end
65
- end
66
-
@@ -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