rspec-expectations 2.14.0 → 3.13.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 (155) 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 +976 -25
  6. data/{License.txt → LICENSE.md} +5 -3
  7. data/README.md +162 -26
  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 +127 -51
  11. data/lib/rspec/expectations/fail_with.rb +17 -57
  12. data/lib/rspec/expectations/failure_aggregator.rb +229 -0
  13. data/lib/rspec/expectations/handler.rb +146 -32
  14. data/lib/rspec/expectations/minitest_integration.rb +58 -0
  15. data/lib/rspec/expectations/syntax.rb +68 -100
  16. data/lib/rspec/expectations/version.rb +1 -1
  17. data/lib/rspec/expectations.rb +58 -23
  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 +191 -20
  21. data/lib/rspec/matchers/built_in/be.rb +114 -114
  22. data/lib/rspec/matchers/built_in/be_between.rb +77 -0
  23. data/lib/rspec/matchers/built_in/be_instance_of.rb +15 -4
  24. data/lib/rspec/matchers/built_in/be_kind_of.rb +10 -1
  25. data/lib/rspec/matchers/built_in/be_within.rb +35 -18
  26. data/lib/rspec/matchers/built_in/change.rb +389 -80
  27. data/lib/rspec/matchers/built_in/compound.rb +290 -0
  28. data/lib/rspec/matchers/built_in/contain_exactly.rb +310 -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 +30 -8
  32. data/lib/rspec/matchers/built_in/eql.rb +23 -8
  33. data/lib/rspec/matchers/built_in/equal.rb +55 -22
  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 +184 -32
  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 +192 -44
  42. data/lib/rspec/matchers/built_in/respond_to.rb +154 -28
  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 +240 -161
  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 +531 -10
  50. data/lib/rspec/matchers/english_phrasing.rb +58 -0
  51. data/lib/rspec/matchers/fail_matchers.rb +42 -0
  52. data/lib/rspec/matchers/generated_descriptions.rb +14 -8
  53. data/lib/rspec/matchers/matcher_delegator.rb +61 -0
  54. data/lib/rspec/matchers/matcher_protocol.rb +105 -0
  55. data/lib/rspec/matchers/multi_matcher_diff.rb +82 -0
  56. data/lib/rspec/matchers.rb +520 -173
  57. data.tar.gz.sig +0 -0
  58. metadata +141 -242
  59. metadata.gz.sig +2 -0
  60. data/features/README.md +0 -48
  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 -175
  64. data/features/built_in_matchers/be_within.feature +0 -48
  65. data/features/built_in_matchers/cover.feature +0 -47
  66. data/features/built_in_matchers/end_with.feature +0 -48
  67. data/features/built_in_matchers/equality.feature +0 -139
  68. data/features/built_in_matchers/exist.feature +0 -45
  69. data/features/built_in_matchers/expect_change.feature +0 -59
  70. data/features/built_in_matchers/expect_error.feature +0 -144
  71. data/features/built_in_matchers/have.feature +0 -109
  72. data/features/built_in_matchers/include.feature +0 -174
  73. data/features/built_in_matchers/match.feature +0 -52
  74. data/features/built_in_matchers/operators.feature +0 -227
  75. data/features/built_in_matchers/predicates.feature +0 -137
  76. data/features/built_in_matchers/respond_to.feature +0 -84
  77. data/features/built_in_matchers/satisfy.feature +0 -33
  78. data/features/built_in_matchers/start_with.feature +0 -48
  79. data/features/built_in_matchers/throw_symbol.feature +0 -91
  80. data/features/built_in_matchers/types.feature +0 -116
  81. data/features/built_in_matchers/yield.feature +0 -161
  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 -368
  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 -14
  92. data/features/syntax_configuration.feature +0 -71
  93. data/features/test_frameworks/test_unit.feature +0 -44
  94. data/lib/rspec/expectations/deprecation.rb +0 -17
  95. data/lib/rspec/expectations/differ.rb +0 -133
  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 -29
  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 -124
  102. data/lib/rspec/matchers/built_in/match_array.rb +0 -51
  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 -108
  106. data/lib/rspec/matchers/extensions/instance_eval_with_args.rb +0 -39
  107. data/lib/rspec/matchers/matcher.rb +0 -300
  108. data/lib/rspec/matchers/method_missing.rb +0 -12
  109. data/lib/rspec/matchers/operator_matcher.rb +0 -109
  110. data/lib/rspec/matchers/pretty.rb +0 -70
  111. data/lib/rspec/matchers/test_unit_integration.rb +0 -11
  112. data/lib/rspec-expectations.rb +0 -1
  113. data/spec/rspec/expectations/differ_spec.rb +0 -192
  114. data/spec/rspec/expectations/expectation_target_spec.rb +0 -82
  115. data/spec/rspec/expectations/extensions/kernel_spec.rb +0 -67
  116. data/spec/rspec/expectations/fail_with_spec.rb +0 -114
  117. data/spec/rspec/expectations/handler_spec.rb +0 -227
  118. data/spec/rspec/expectations/syntax_spec.rb +0 -139
  119. data/spec/rspec/matchers/base_matcher_spec.rb +0 -62
  120. data/spec/rspec/matchers/be_close_spec.rb +0 -22
  121. data/spec/rspec/matchers/be_instance_of_spec.rb +0 -63
  122. data/spec/rspec/matchers/be_kind_of_spec.rb +0 -41
  123. data/spec/rspec/matchers/be_spec.rb +0 -516
  124. data/spec/rspec/matchers/be_within_spec.rb +0 -137
  125. data/spec/rspec/matchers/change_spec.rb +0 -553
  126. data/spec/rspec/matchers/configuration_spec.rb +0 -206
  127. data/spec/rspec/matchers/cover_spec.rb +0 -69
  128. data/spec/rspec/matchers/description_generation_spec.rb +0 -190
  129. data/spec/rspec/matchers/dsl_spec.rb +0 -57
  130. data/spec/rspec/matchers/eq_spec.rb +0 -60
  131. data/spec/rspec/matchers/eql_spec.rb +0 -41
  132. data/spec/rspec/matchers/equal_spec.rb +0 -78
  133. data/spec/rspec/matchers/exist_spec.rb +0 -124
  134. data/spec/rspec/matchers/has_spec.rb +0 -122
  135. data/spec/rspec/matchers/have_spec.rb +0 -455
  136. data/spec/rspec/matchers/include_matcher_integration_spec.rb +0 -30
  137. data/spec/rspec/matchers/include_spec.rb +0 -531
  138. data/spec/rspec/matchers/match_array_spec.rb +0 -194
  139. data/spec/rspec/matchers/match_spec.rb +0 -61
  140. data/spec/rspec/matchers/matcher_spec.rb +0 -471
  141. data/spec/rspec/matchers/matchers_spec.rb +0 -37
  142. data/spec/rspec/matchers/method_missing_spec.rb +0 -28
  143. data/spec/rspec/matchers/operator_matcher_spec.rb +0 -223
  144. data/spec/rspec/matchers/raise_error_spec.rb +0 -485
  145. data/spec/rspec/matchers/respond_to_spec.rb +0 -292
  146. data/spec/rspec/matchers/satisfy_spec.rb +0 -44
  147. data/spec/rspec/matchers/start_with_end_with_spec.rb +0 -186
  148. data/spec/rspec/matchers/throw_symbol_spec.rb +0 -116
  149. data/spec/rspec/matchers/yield_spec.rb +0 -514
  150. data/spec/spec_helper.rb +0 -54
  151. data/spec/support/classes.rb +0 -56
  152. data/spec/support/in_sub_process.rb +0 -38
  153. data/spec/support/matchers.rb +0 -22
  154. data/spec/support/ruby_version.rb +0 -10
  155. 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,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,108 +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
- # color config for expectations
43
- # fallback if rspec core not available
44
- if ::RSpec.respond_to?(:configuration)
45
- def color?
46
- ::RSpec.configuration.color_enabled?
47
- end
48
- else
49
- attr_writer :color
50
- def color?
51
- @color
52
- end
53
- end
54
-
55
- # Adds `should` and `should_not` to the given classes
56
- # or modules. This can be used to ensure `should` works
57
- # properly on things like proxy objects (particular
58
- # `Delegator`-subclassed objects on 1.8).
59
- #
60
- # @param [Array<Module>] modules the list of classes or modules
61
- # to add `should` and `should_not` to.
62
- def add_should_and_should_not_to(*modules)
63
- modules.each do |mod|
64
- Expectations::Syntax.enable_should(mod)
65
- end
66
- end
67
-
68
- # Sets or gets the backtrace formatter. The backtrace formatter should
69
- # implement `#format_backtrace(Array<String>)`. This is used
70
- # to format backtraces of errors handled by the `raise_error`
71
- # matcher.
72
- #
73
- # If you are using rspec-core, rspec-core's backtrace formatting
74
- # will be used (including respecting the presence or absence of
75
- # the `--backtrace` option).
76
- #
77
- # @overload backtrace_formatter
78
- # @return [#format_backtrace] the backtrace formatter
79
- # @overload backtrace_formatter=
80
- # @param value [#format_backtrace] sets the backtrace formatter
81
- attr_writer :backtrace_formatter
82
- def backtrace_formatter
83
- @backtrace_formatter ||= if defined?(::RSpec::Core::BacktraceFormatter)
84
- ::RSpec::Core::BacktraceFormatter
85
- else
86
- NullBacktraceFormatter
87
- end
88
- end
89
-
90
- # @api private
91
- NullBacktraceFormatter = Module.new do
92
- def self.format_backtrace(backtrace)
93
- backtrace
94
- end
95
- end
96
- end
97
-
98
- # The configuration object
99
- # @return [RSpec::Matchers::Configuration] the configuration object
100
- def self.configuration
101
- @configuration ||= Configuration.new
102
- end
103
-
104
- # set default syntax
105
- configuration.syntax = [:expect, :should]
106
- end
107
- end
108
-
@@ -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