rspec-expectations 2.0.0.beta.8 → 2.0.0.beta.9
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.
- data/README.markdown +1 -1
- data/Rakefile +8 -7
- data/Upgrade.markdown +6 -6
- data/VERSION +1 -1
- data/features/expectations/customized_message.feature +1 -1
- data/features/expectations/implicit_docstrings.feature +2 -2
- data/features/matchers/access_running_example.feature +5 -5
- data/features/matchers/define_diffable_matcher.feature +2 -2
- data/features/matchers/define_matcher.feature +14 -14
- data/features/matchers/define_matcher_outside_rspec.feature +2 -2
- data/features/matchers/define_matcher_with_fluent_interface.feature +2 -2
- data/features/matchers/expect_change.feature +2 -2
- data/features/matchers/expect_error.feature +2 -2
- data/lib/rspec/expectations.rb +7 -5
- data/lib/rspec/expectations/backward_compatibility.rb +16 -0
- data/lib/rspec/expectations/differ.rb +58 -0
- data/lib/rspec/expectations/errors.rb +1 -1
- data/lib/rspec/expectations/extensions/kernel.rb +4 -4
- data/lib/rspec/expectations/extensions/rspec/core/example_group.rb +1 -1
- data/lib/rspec/expectations/fail_with.rb +6 -4
- data/lib/rspec/expectations/handler.rb +11 -11
- data/lib/rspec/expectations/version.rb +1 -1
- data/lib/rspec/matchers.rb +7 -8
- data/lib/rspec/matchers/be.rb +6 -6
- data/lib/rspec/matchers/be_close.rb +1 -1
- data/lib/rspec/matchers/be_instance_of.rb +1 -1
- data/lib/rspec/matchers/be_kind_of.rb +1 -1
- data/lib/rspec/matchers/change.rb +1 -1
- data/lib/rspec/matchers/compatibility.rb +2 -2
- data/lib/rspec/matchers/dsl.rb +4 -4
- data/lib/rspec/matchers/eq.rb +1 -1
- data/lib/rspec/matchers/eql.rb +1 -1
- data/lib/rspec/matchers/equal.rb +1 -1
- data/lib/rspec/matchers/errors.rb +1 -1
- data/lib/rspec/matchers/exist.rb +1 -1
- data/lib/rspec/matchers/extensions/instance_exec.rb +1 -1
- data/lib/rspec/matchers/generated_descriptions.rb +1 -1
- data/lib/rspec/matchers/has.rb +1 -1
- data/lib/rspec/matchers/have.rb +1 -1
- data/lib/rspec/matchers/include.rb +1 -1
- data/lib/rspec/matchers/match.rb +1 -1
- data/lib/rspec/matchers/match_array.rb +3 -3
- data/lib/rspec/matchers/matcher.rb +13 -13
- data/lib/rspec/matchers/method_missing.rb +1 -1
- data/lib/rspec/matchers/operator_matcher.rb +4 -4
- data/lib/rspec/matchers/pretty.rb +1 -1
- data/lib/rspec/matchers/raise_error.rb +1 -1
- data/lib/rspec/matchers/respond_to.rb +1 -1
- data/lib/rspec/matchers/satisfy.rb +1 -1
- data/lib/rspec/matchers/throw_symbol.rb +1 -1
- data/rspec-expectations.gemspec +17 -14
- data/spec/rspec/expectations/{differs/default_spec.rb → differ_spec.rb} +4 -36
- data/spec/rspec/expectations/fail_with_spec.rb +6 -50
- data/spec/rspec/expectations/handler_spec.rb +22 -22
- data/spec/rspec/matchers/be_close_spec.rb +1 -1
- data/spec/rspec/matchers/be_instance_of_spec.rb +1 -1
- data/spec/rspec/matchers/be_kind_of_spec.rb +1 -1
- data/spec/rspec/matchers/change_spec.rb +3 -3
- data/spec/rspec/matchers/compatibility_spec.rb +3 -3
- data/spec/rspec/matchers/description_generation_spec.rb +28 -28
- data/spec/rspec/matchers/dsl_spec.rb +3 -3
- data/spec/rspec/matchers/eq_spec.rb +1 -1
- data/spec/rspec/matchers/eql_spec.rb +1 -1
- data/spec/rspec/matchers/equal_spec.rb +1 -1
- data/spec/rspec/matchers/exist_spec.rb +1 -1
- data/spec/rspec/matchers/have_spec.rb +3 -3
- data/spec/rspec/matchers/match_array_spec.rb +3 -0
- data/spec/rspec/matchers/matcher_spec.rb +25 -25
- data/spec/rspec/matchers/operator_matcher_spec.rb +12 -12
- data/spec/rspec/matchers/throw_symbol_spec.rb +1 -1
- data/spec/spec_helper.rb +6 -7
- data/spec/support/classes.rb +1 -1
- metadata +35 -21
- data/lib/rspec/expectations/differs/default.rb +0 -62
- data/lib/rspec/expectations/differs/load-diff-lcs.rb +0 -7
data/README.markdown
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# RSpec Expectations
|
2
2
|
|
3
3
|
rspec-expectations adds `should` and `should_not` to every object and includes
|
4
|
-
|
4
|
+
RSpec::Matchers, a library of standard matchers.
|
5
5
|
|
6
6
|
rspec-expectations is currently in alpha release. While you are welcome to
|
7
7
|
track, fork, explore, etc, we're too early in the process to start fielding
|
data/Rakefile
CHANGED
@@ -6,17 +6,18 @@ begin
|
|
6
6
|
require 'jeweler'
|
7
7
|
Jeweler::Tasks.new do |gem|
|
8
8
|
gem.name = "rspec-expectations"
|
9
|
-
gem.version =
|
10
|
-
gem.summary = "rspec-expectations-#{
|
9
|
+
gem.version = RSpec::Expectations::Version::STRING
|
10
|
+
gem.summary = "rspec-expectations-#{RSpec::Expectations::Version::STRING}"
|
11
11
|
gem.description = "rspec expectations (should[_not] and matchers)"
|
12
12
|
gem.rubyforge_project = "rspec"
|
13
13
|
gem.email = "dchelimsky@gmail.com;chad.humphries@gmail.com"
|
14
14
|
gem.homepage = "http://github.com/rspec/expectations"
|
15
15
|
gem.authors = ["David Chelimsky", "Chad Humphries"]
|
16
|
+
gem.add_dependency('diff-lcs', ">= 1.1.2")
|
16
17
|
gem.add_development_dependency('cucumber', ">= 0.6.2")
|
17
18
|
gem.add_development_dependency('aruba', ">= 0.1.1")
|
18
|
-
gem.add_development_dependency('rspec-core', ">= #{
|
19
|
-
gem.add_development_dependency('rspec-mocks', ">= #{
|
19
|
+
gem.add_development_dependency('rspec-core', ">= #{RSpec::Expectations::Version::STRING}")
|
20
|
+
gem.add_development_dependency('rspec-mocks', ">= #{RSpec::Expectations::Version::STRING}")
|
20
21
|
gem.post_install_message = <<-EOM
|
21
22
|
#{"*"*50}
|
22
23
|
|
@@ -36,15 +37,15 @@ end
|
|
36
37
|
namespace :gem do
|
37
38
|
desc "push to gemcutter"
|
38
39
|
task :push => :build do
|
39
|
-
system "gem push pkg/rspec-expectations-#{
|
40
|
+
system "gem push pkg/rspec-expectations-#{RSpec::Expectations::Version::STRING}.gem"
|
40
41
|
end
|
41
42
|
end
|
42
43
|
|
43
44
|
begin
|
44
45
|
require 'rspec/core/rake_task'
|
45
|
-
|
46
|
+
RSpec::Core::RakeTask.new(:spec)
|
46
47
|
rescue LoadError
|
47
|
-
puts "
|
48
|
+
puts "RSpec core or one of its dependencies is not installed. Install it with: gem install rspec-core"
|
48
49
|
end
|
49
50
|
|
50
51
|
begin
|
data/Upgrade.markdown
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
### New `eq` matcher.
|
6
6
|
|
7
|
-
`
|
7
|
+
`RSpec::Matchers` now offers you two approaches to differentiating between
|
8
8
|
object identity. You can use the rspec-1 approach:
|
9
9
|
|
10
10
|
actual.should == expected # object equality
|
@@ -19,7 +19,7 @@ object identity. You can use the rspec-1 approach:
|
|
19
19
|
|
20
20
|
### simple_matcher
|
21
21
|
|
22
|
-
Use
|
22
|
+
Use RSpec::Matchers.define instead. For example, if you had:
|
23
23
|
|
24
24
|
def eat_cheese
|
25
25
|
simple_matcher("eat cheese") do |actual|
|
@@ -29,7 +29,7 @@ Use Rspec::Matchers.define instead. For example, if you had:
|
|
29
29
|
|
30
30
|
Change it to:
|
31
31
|
|
32
|
-
|
32
|
+
RSpec::Matchers.define :eat_cheese do
|
33
33
|
match do |actual|
|
34
34
|
actual.eat?(:cheese)
|
35
35
|
end
|
@@ -37,15 +37,15 @@ Change it to:
|
|
37
37
|
|
38
38
|
### wrap_expectation
|
39
39
|
|
40
|
-
Use
|
40
|
+
Use RSpec::Matchers.define instead.
|
41
41
|
|
42
|
-
|
42
|
+
RSpec::Matchers.define :eat_cheese do
|
43
43
|
match do |actual|
|
44
44
|
actual.should eat?(:cheese)
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
|
48
|
+
RSpec::Matchers.define :eat_cheese do
|
49
49
|
include MyCheesyAssertions
|
50
50
|
match_unless_raises Test::Unit::AssertionFailedError do |actual|
|
51
51
|
assert_eats_chesse actual
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.0.0.beta.
|
1
|
+
2.0.0.beta.9
|
@@ -45,7 +45,7 @@ Feature: customized message
|
|
45
45
|
end
|
46
46
|
|
47
47
|
"""
|
48
|
-
When I run "rspec node_spec.rb --format documentation"
|
48
|
+
When I run "rspec ./node_spec.rb --format documentation"
|
49
49
|
Then I should see "3 examples, 3 failures"
|
50
50
|
And I should not see "to return true, got false"
|
51
51
|
And I should not see "to return false, got true"
|
@@ -18,7 +18,7 @@ Feature: implicit docstrings
|
|
18
18
|
end
|
19
19
|
"""
|
20
20
|
|
21
|
-
When I run "rspec implicit_docstrings_spec.rb -fdoc"
|
21
|
+
When I run "rspec ./implicit_docstrings_spec.rb -fdoc"
|
22
22
|
|
23
23
|
Then I should see "should be < 5"
|
24
24
|
And I should see "should include 2"
|
@@ -44,7 +44,7 @@ Feature: implicit docstrings
|
|
44
44
|
end
|
45
45
|
"""
|
46
46
|
|
47
|
-
When I run "rspec failing_implicit_docstrings_spec.rb -fdoc"
|
47
|
+
When I run "rspec ./failing_implicit_docstrings_spec.rb -fdoc"
|
48
48
|
|
49
49
|
Then I should see "should equal 2"
|
50
50
|
And I should see "should be > 5"
|
@@ -12,7 +12,7 @@ Feature: access running example
|
|
12
12
|
Scenario: call method defined on example from matcher
|
13
13
|
Given a file named "example_spec.rb" with:
|
14
14
|
"""
|
15
|
-
|
15
|
+
RSpec::Matchers.define :bar do
|
16
16
|
match do |_|
|
17
17
|
foo == "foo"
|
18
18
|
end
|
@@ -28,13 +28,13 @@ Feature: access running example
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
"""
|
31
|
-
When I run "rspec example_spec.rb"
|
31
|
+
When I run "rspec ./example_spec.rb"
|
32
32
|
Then I should see "1 example, 0 failures"
|
33
33
|
|
34
34
|
Scenario: call method _not_ defined on example from matcher
|
35
35
|
Given a file named "example_spec.rb" with:
|
36
36
|
"""
|
37
|
-
|
37
|
+
RSpec::Matchers.define :bar do
|
38
38
|
match do |_|
|
39
39
|
foo == "foo"
|
40
40
|
end
|
@@ -46,8 +46,8 @@ Feature: access running example
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
"""
|
49
|
-
When I run "rspec example_spec.rb"
|
49
|
+
When I run "rspec ./example_spec.rb"
|
50
50
|
Then I should see "1 example, 1 failure"
|
51
51
|
And I should see "undefined local variable"
|
52
|
-
And I should see "
|
52
|
+
And I should see "RSpec::Matchers::Matcher"
|
53
53
|
And I should not see "ExampleGroup"
|
@@ -8,7 +8,7 @@ Feature: define diffable matcher
|
|
8
8
|
Scenario: define a diffable matcher
|
9
9
|
Given a file named "diffable_matcher_spec.rb" with:
|
10
10
|
"""
|
11
|
-
|
11
|
+
RSpec::Matchers.define :be_just_like do |expected|
|
12
12
|
match do |actual|
|
13
13
|
actual == expected
|
14
14
|
end
|
@@ -20,7 +20,7 @@ Feature: define diffable matcher
|
|
20
20
|
it {should be_just_like("that")}
|
21
21
|
end
|
22
22
|
"""
|
23
|
-
When I run "rspec diffable_matcher_spec.rb --diff"
|
23
|
+
When I run "rspec ./diffable_matcher_spec.rb --diff"
|
24
24
|
Then the exit status should not be 0
|
25
25
|
|
26
26
|
And I should see "should be just like that"
|
@@ -9,7 +9,7 @@ Feature: define matcher
|
|
9
9
|
"""
|
10
10
|
require 'rspec/expectations'
|
11
11
|
|
12
|
-
|
12
|
+
RSpec::Matchers.define :be_a_multiple_of do |expected|
|
13
13
|
match do |actual|
|
14
14
|
actual % expected == 0
|
15
15
|
end
|
@@ -34,7 +34,7 @@ Feature: define matcher
|
|
34
34
|
end
|
35
35
|
|
36
36
|
"""
|
37
|
-
When I run "rspec matcher_with_default_message_spec.rb --format documentation"
|
37
|
+
When I run "rspec ./matcher_with_default_message_spec.rb --format documentation"
|
38
38
|
Then the exit status should not be 0
|
39
39
|
|
40
40
|
And I should see "should be a multiple of 3"
|
@@ -51,7 +51,7 @@ Feature: define matcher
|
|
51
51
|
"""
|
52
52
|
require 'rspec/expectations'
|
53
53
|
|
54
|
-
|
54
|
+
RSpec::Matchers.define :be_a_multiple_of do |expected|
|
55
55
|
match do |actual|
|
56
56
|
actual % expected == 0
|
57
57
|
end
|
@@ -65,7 +65,7 @@ Feature: define matcher
|
|
65
65
|
it {should be_a_multiple_of(4)}
|
66
66
|
end
|
67
67
|
"""
|
68
|
-
When I run "rspec matcher_with_failure_message_spec.rb"
|
68
|
+
When I run "rspec ./matcher_with_failure_message_spec.rb"
|
69
69
|
Then the exit status should not be 0
|
70
70
|
And the stdout should contain "1 example, 1 failure"
|
71
71
|
And the stdout should contain "expected that 9 would be a multiple of 4"
|
@@ -75,7 +75,7 @@ Feature: define matcher
|
|
75
75
|
"""
|
76
76
|
require 'rspec/expectations'
|
77
77
|
|
78
|
-
|
78
|
+
RSpec::Matchers.define :be_a_multiple_of do |expected|
|
79
79
|
match do |actual|
|
80
80
|
actual % expected == 0
|
81
81
|
end
|
@@ -89,7 +89,7 @@ Feature: define matcher
|
|
89
89
|
it {should_not be_a_multiple_of(3)}
|
90
90
|
end
|
91
91
|
"""
|
92
|
-
When I run "rspec matcher_with_failure_for_message_spec.rb"
|
92
|
+
When I run "rspec ./matcher_with_failure_for_message_spec.rb"
|
93
93
|
Then the exit status should not be 0
|
94
94
|
And the stdout should contain "1 example, 1 failure"
|
95
95
|
And the stdout should contain "expected that 9 would not be a multiple of 3"
|
@@ -99,7 +99,7 @@ Feature: define matcher
|
|
99
99
|
"""
|
100
100
|
require 'rspec/expectations'
|
101
101
|
|
102
|
-
|
102
|
+
RSpec::Matchers.define :be_a_multiple_of do |expected|
|
103
103
|
match do |actual|
|
104
104
|
actual % expected == 0
|
105
105
|
end
|
@@ -116,7 +116,7 @@ Feature: define matcher
|
|
116
116
|
it {should_not be_a_multiple_of(4)}
|
117
117
|
end
|
118
118
|
"""
|
119
|
-
When I run "rspec matcher_overriding_description_spec.rb --format documentation"
|
119
|
+
When I run "rspec ./matcher_overriding_description_spec.rb --format documentation"
|
120
120
|
Then the exit status should be 0
|
121
121
|
And the stdout should contain "2 examples, 0 failures"
|
122
122
|
And the stdout should contain "should be multiple of 3"
|
@@ -127,7 +127,7 @@ Feature: define matcher
|
|
127
127
|
"""
|
128
128
|
require 'rspec/expectations'
|
129
129
|
|
130
|
-
|
130
|
+
RSpec::Matchers.define :have_7_fingers do
|
131
131
|
match do |thing|
|
132
132
|
thing.fingers.length == 7
|
133
133
|
end
|
@@ -141,7 +141,7 @@ Feature: define matcher
|
|
141
141
|
it {should have_7_fingers}
|
142
142
|
end
|
143
143
|
"""
|
144
|
-
When I run "rspec matcher_with_no_args_spec.rb --format documentation"
|
144
|
+
When I run "rspec ./matcher_with_no_args_spec.rb --format documentation"
|
145
145
|
Then the exit status should be 0
|
146
146
|
And the stdout should contain "1 example, 0 failures"
|
147
147
|
And the stdout should contain "should have 7 fingers"
|
@@ -151,7 +151,7 @@ Feature: define matcher
|
|
151
151
|
"""
|
152
152
|
require 'rspec/expectations'
|
153
153
|
|
154
|
-
|
154
|
+
RSpec::Matchers.define :be_the_sum_of do |a,b,c,d|
|
155
155
|
match do |sum|
|
156
156
|
a + b + c + d == sum
|
157
157
|
end
|
@@ -161,7 +161,7 @@ Feature: define matcher
|
|
161
161
|
it {should be_the_sum_of(1,2,3,4)}
|
162
162
|
end
|
163
163
|
"""
|
164
|
-
When I run "rspec matcher_with_multiple_args_spec.rb --format documentation"
|
164
|
+
When I run "rspec ./matcher_with_multiple_args_spec.rb --format documentation"
|
165
165
|
Then the exit status should be 0
|
166
166
|
And the stdout should contain "1 example, 0 failures"
|
167
167
|
And the stdout should contain "should be the sum of 1, 2, 3, and 4"
|
@@ -171,7 +171,7 @@ Feature: define matcher
|
|
171
171
|
"""
|
172
172
|
require 'rspec/expectations'
|
173
173
|
|
174
|
-
|
174
|
+
RSpec::Matchers.define :have_same_elements_as do |sample|
|
175
175
|
match do |actual|
|
176
176
|
similar?(sample, actual)
|
177
177
|
end
|
@@ -187,7 +187,7 @@ Feature: define matcher
|
|
187
187
|
end
|
188
188
|
end
|
189
189
|
"""
|
190
|
-
When I run "rspec matcher_with_internal_helper_spec.rb"
|
190
|
+
When I run "rspec ./matcher_with_internal_helper_spec.rb"
|
191
191
|
Then the exit status should be 0
|
192
192
|
And the stdout should contain "1 example, 0 failures"
|
193
193
|
|
@@ -10,14 +10,14 @@ Feature: define matcher outside rspec
|
|
10
10
|
require "rspec/expectations"
|
11
11
|
require "test/unit"
|
12
12
|
|
13
|
-
|
13
|
+
RSpec::Matchers.define :be_a_multiple_of do |expected|
|
14
14
|
match do |actual|
|
15
15
|
actual % expected == 0
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
class Test::Unit::TestCase
|
20
|
-
include
|
20
|
+
include RSpec::Matchers
|
21
21
|
end
|
22
22
|
|
23
23
|
class TestMultiples < Test::Unit::TestCase
|
@@ -7,7 +7,7 @@ Feature: define matcher
|
|
7
7
|
Scenario: one additional method
|
8
8
|
Given a file named "between_spec.rb" with:
|
9
9
|
"""
|
10
|
-
|
10
|
+
RSpec::Matchers.define :be_bigger_than do |first|
|
11
11
|
def but_smaller_than(second)
|
12
12
|
@second = second
|
13
13
|
self
|
@@ -22,6 +22,6 @@ Feature: define matcher
|
|
22
22
|
it { should be_bigger_than(4).but_smaller_than(6) }
|
23
23
|
end
|
24
24
|
"""
|
25
|
-
When I run "rspec between_spec.rb --format documentation"
|
25
|
+
When I run "rspec ./between_spec.rb --format documentation"
|
26
26
|
Then I should see "1 example, 0 failures"
|
27
27
|
And I should see "should be bigger than 4"
|
@@ -29,7 +29,7 @@ Feature: expect change
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
"""
|
32
|
-
When I run "rspec expect_change_spec.rb"
|
32
|
+
When I run "rspec ./expect_change_spec.rb"
|
33
33
|
Then I should see "2 examples, 1 failure"
|
34
34
|
Then I should see "should have been changed by 2, but was changed by 1"
|
35
35
|
|
@@ -60,6 +60,6 @@ Feature: expect change
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
"""
|
63
|
-
When I run "rspec expect_no_change_spec.rb"
|
63
|
+
When I run "rspec ./expect_no_change_spec.rb"
|
64
64
|
Then I should see "2 examples, 1 failure"
|
65
65
|
Then I should see "should not have changed, but did change from 1 to 2"
|
@@ -18,7 +18,7 @@ Feature: expect error
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
"""
|
21
|
-
When I run "rspec expect_error_spec.rb"
|
21
|
+
When I run "rspec ./expect_error_spec.rb"
|
22
22
|
Then I should see "2 examples, 1 failure"
|
23
23
|
Then I should see "expected NameError but nothing was raised"
|
24
24
|
|
@@ -38,7 +38,7 @@ Feature: expect error
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
"""
|
41
|
-
When I run "rspec expect_no_error_spec.rb"
|
41
|
+
When I run "rspec ./expect_no_error_spec.rb"
|
42
42
|
Then I should see "2 examples, 1 failure"
|
43
43
|
Then I should see "undefined method `non_existent_message'"
|
44
44
|
|
data/lib/rspec/expectations.rb
CHANGED
@@ -4,22 +4,24 @@ require 'rspec/expectations/errors'
|
|
4
4
|
require 'rspec/expectations/extensions'
|
5
5
|
require 'rspec/expectations/handler'
|
6
6
|
require 'rspec/expectations/version'
|
7
|
+
require 'rspec/expectations/backward_compatibility'
|
8
|
+
require 'rspec/expectations/differ'
|
7
9
|
|
8
|
-
module
|
10
|
+
module RSpec
|
9
11
|
|
10
|
-
#
|
12
|
+
# RSpec::Expectations lets you set expectations on your objects.
|
11
13
|
#
|
12
14
|
# result.should == 37
|
13
15
|
# team.should have(11).players_on_the_field
|
14
16
|
#
|
15
17
|
# == How Expectations work.
|
16
18
|
#
|
17
|
-
#
|
19
|
+
# RSpec::Expectations adds two methods to Object:
|
18
20
|
#
|
19
21
|
# should(matcher=nil)
|
20
22
|
# should_not(matcher=nil)
|
21
23
|
#
|
22
|
-
# Both methods take an optional Expression Matcher (See
|
24
|
+
# Both methods take an optional Expression Matcher (See RSpec::Matchers).
|
23
25
|
#
|
24
26
|
# When +should+ receives an Expression Matcher, it calls <tt>matches?(self)</tt>. If
|
25
27
|
# it returns +true+, the spec passes and execution continues. If it returns
|
@@ -30,7 +32,7 @@ module Rspec
|
|
30
32
|
# +true+, then the spec fails with the message returned by <tt>matcher.negative_failure_message</tt>.
|
31
33
|
#
|
32
34
|
# RSpec ships with a standard set of useful matchers, and writing your own
|
33
|
-
# matchers is quite simple. See
|
35
|
+
# matchers is quite simple. See RSpec::Matchers for details.
|
34
36
|
module Expectations
|
35
37
|
end
|
36
38
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# Cucumber 0.7 includes Rspec::Expectations
|
2
|
+
module RSpec
|
3
|
+
module Expectations
|
4
|
+
module ConstMissing
|
5
|
+
def const_missing(name)
|
6
|
+
name == :Rspec ? RSpec : super(name)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def differ=(ignore)
|
11
|
+
RSpec.deprecate("RSpec::Expectations.differ=(differ)", "nothing at all (diffing is now automatic and no longer configurable)")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
Object.extend(RSpec::Expectations::ConstMissing)
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'diff/lcs'
|
2
|
+
require 'diff/lcs/hunk'
|
3
|
+
require 'pp'
|
4
|
+
|
5
|
+
module RSpec
|
6
|
+
module Expectations
|
7
|
+
class Differ
|
8
|
+
def initialize(ignore=nil)
|
9
|
+
end
|
10
|
+
|
11
|
+
# This is snagged from diff/lcs/ldiff.rb (which is a commandline tool)
|
12
|
+
def diff_as_string(data_new, data_old)
|
13
|
+
data_old = data_old.split(/\n/).map! { |e| e.chomp }
|
14
|
+
data_new = data_new.split(/\n/).map! { |e| e.chomp }
|
15
|
+
output = ""
|
16
|
+
diffs = Diff::LCS.diff(data_old, data_new)
|
17
|
+
return output if diffs.empty?
|
18
|
+
oldhunk = hunk = nil
|
19
|
+
file_length_difference = 0
|
20
|
+
diffs.each do |piece|
|
21
|
+
begin
|
22
|
+
hunk = Diff::LCS::Hunk.new(data_old, data_new, piece, context_lines,
|
23
|
+
file_length_difference)
|
24
|
+
file_length_difference = hunk.file_length_difference
|
25
|
+
next unless oldhunk
|
26
|
+
# Hunks may overlap, which is why we need to be careful when our
|
27
|
+
# diff includes lines of context. Otherwise, we might print
|
28
|
+
# redundant lines.
|
29
|
+
if (context_lines > 0) and hunk.overlaps?(oldhunk)
|
30
|
+
hunk.unshift(oldhunk)
|
31
|
+
else
|
32
|
+
output << oldhunk.diff(format)
|
33
|
+
end
|
34
|
+
ensure
|
35
|
+
oldhunk = hunk
|
36
|
+
output << "\n"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
#Handle the last remaining hunk
|
40
|
+
output << oldhunk.diff(format) << "\n"
|
41
|
+
end
|
42
|
+
|
43
|
+
def diff_as_object(target,expected)
|
44
|
+
diff_as_string(PP.pp(target,""), PP.pp(expected,""))
|
45
|
+
end
|
46
|
+
|
47
|
+
protected
|
48
|
+
def format
|
49
|
+
:unified
|
50
|
+
end
|
51
|
+
|
52
|
+
def context_lines
|
53
|
+
3
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|