Skip to content

Commit 67a3369

Browse files
committed
Update matcher protocol for RSpec 3
"Update matcher protocol and custom matcher DSL to better align with the newer expect syntax. If you want your matchers to maintain compatibility with multiple versions of RSpec, you can alias the new names to the old. (Myron Marston) * failure_message_for_should => failure_message * failure_message_for_should_not => failure_message_when_negated * match_for_should => match * match_for_should_not => match_when_negated" http://myronmars.to/n/dev-blog/2014/02/rspec-2-99-and-3-0-beta-2-have-been-released
1 parent b48f7cb commit 67a3369

File tree

7 files changed

+32
-18
lines changed

7 files changed

+32
-18
lines changed

lib/json_spec/matchers/be_json_eql.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,15 @@ def including(*keys)
4242
self
4343
end
4444

45-
def failure_message_for_should
45+
def failure_message
4646
message_with_path("Expected equivalent JSON")
4747
end
48+
alias :failure_message_for_should :failure_message
4849

49-
def failure_message_for_should_not
50+
def failure_message_when_negated
5051
message_with_path("Expected inequivalent JSON")
5152
end
53+
alias :failure_message_for_should_not :failure_message_when_negated
5254

5355
def description
5456
message_with_path("equal JSON")

lib/json_spec/matchers/have_json_path.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ def matches?(json)
1414
false
1515
end
1616

17-
def failure_message_for_should
17+
def failure_message
1818
%(Expected JSON path "#{@path}")
1919
end
20+
alias :failure_message_for_should :failure_message
2021

21-
def failure_message_for_should_not
22+
def failure_message_when_negated
2223
%(Expected no JSON path "#{@path}")
2324
end
25+
alias :failure_message_for_should_not :failure_message_when_negated
2426

2527
def description
2628
%(have JSON path "#{@path}")

lib/json_spec/matchers/have_json_size.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ def at_path(path)
1919
self
2020
end
2121

22-
def failure_message_for_should
22+
def failure_message
2323
message_with_path("Expected JSON value size to be #{@expected}, got #{@actual}")
2424
end
25+
alias :failure_message_for_should :failure_message
2526

26-
def failure_message_for_should_not
27+
def failure_message_when_negated
2728
message_with_path("Expected JSON value size to not be #{@expected}, got #{@actual}")
2829
end
30+
alias :failure_message_for_should_not :failure_message_when_negated
2931

3032
def description
3133
message_with_path(%(have JSON size "#{@expected}"))

lib/json_spec/matchers/have_json_type.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ def at_path(path)
1818
self
1919
end
2020

21-
def failure_message_for_should
21+
def failure_message
2222
message_with_path("Expected JSON value type to be #{@classes.join(", ")}, got #{@ruby.class}")
2323
end
24+
alias :failure_message_for_should :failure_message
2425

25-
def failure_message_for_should_not
26+
def failure_message_when_negated
2627
message_with_path("Expected JSON value type to not be #{@classes.join(", ")}, got #{@ruby.class}")
2728
end
29+
alias :failure_message_for_should_not :failure_message_when_negated
2830

2931
def description
3032
message_with_path(%(have JSON type "#{@classes.join(", ")}"))

lib/json_spec/matchers/include_json.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,15 @@ def including(*keys)
4242
self
4343
end
4444

45-
def failure_message_for_should
45+
def failure_message
4646
message_with_path("Expected included JSON")
4747
end
48+
alias :failure_message_for_should :failure_message
4849

49-
def failure_message_for_should_not
50+
def failure_message_when_negated
5051
message_with_path("Expected excluded JSON")
5152
end
53+
alias :failure_message_for_should_not :failure_message_when_negated
5254

5355
def description
5456
message_with_path("include JSON")

spec/json_spec/matchers/have_json_size_spec.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,18 @@
2121
%({"one":[1,2,3]}).should have_json_size(3).at_path("one")
2222
end
2323

24-
it "provides a failure message for should" do
24+
it "provides a failure message" do
2525
matcher = have_json_size(3)
2626
matcher.matches?(%([1,2]))
27-
matcher.failure_message_for_should.should == "Expected JSON value size to be 3, got 2"
27+
matcher.failure_message.should == "Expected JSON value size to be 3, got 2"
28+
matcher.failure_message_for_should.should == "Expected JSON value size to be 3, got 2" # RSpec 2 interface
2829
end
2930

30-
it "provides a failure message for should not" do
31+
it "provides a failure message for negation" do
3132
matcher = have_json_size(3)
3233
matcher.matches?(%([1,2,3]))
33-
matcher.failure_message_for_should_not.should == "Expected JSON value size to not be 3, got 3"
34+
matcher.failure_message_when_negated.should == "Expected JSON value size to not be 3, got 3"
35+
matcher.failure_message_for_should_not.should == "Expected JSON value size to not be 3, got 3" # RSpec 2 interface
3436
end
3537

3638
it "provides a description message" do

spec/json_spec/matchers/have_json_type_spec.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,18 @@
4646
%(10.0).should have_json_type(Numeric)
4747
end
4848

49-
it "provides a failure message for should" do
49+
it "provides a failure message" do
5050
matcher = have_json_type(Numeric)
5151
matcher.matches?(%("foo"))
52-
matcher.failure_message_for_should.should == "Expected JSON value type to be Numeric, got String"
52+
matcher.failure_message.should == "Expected JSON value type to be Numeric, got String"
53+
matcher.failure_message_for_should.should == "Expected JSON value type to be Numeric, got String" # RSpec 2 interface
5354
end
5455

55-
it "provides a failure message for should not" do
56+
it "provides a failure message for negation" do
5657
matcher = have_json_type(Numeric)
5758
matcher.matches?(%(10))
58-
matcher.failure_message_for_should_not.should == "Expected JSON value type to not be Numeric, got Fixnum"
59+
matcher.failure_message_when_negated.should == "Expected JSON value type to not be Numeric, got Fixnum"
60+
matcher.failure_message_for_should_not.should == "Expected JSON value type to not be Numeric, got Fixnum" # RSpec 2 interface
5961
end
6062

6163
it "provides a description message" do

0 commit comments

Comments
 (0)