Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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
  • Loading branch information
skalee committed Feb 25, 2014
commit 67a3369e5e8e73bed1c83adae63f68a29726c6ce
6 changes: 4 additions & 2 deletions lib/json_spec/matchers/be_json_eql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ def including(*keys)
self
end

def failure_message_for_should
def failure_message
message_with_path("Expected equivalent JSON")
end
alias :failure_message_for_should :failure_message

def failure_message_for_should_not
def failure_message_when_negated
message_with_path("Expected inequivalent JSON")
end
alias :failure_message_for_should_not :failure_message_when_negated

def description
message_with_path("equal JSON")
Expand Down
6 changes: 4 additions & 2 deletions lib/json_spec/matchers/have_json_path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ def matches?(json)
false
end

def failure_message_for_should
def failure_message
%(Expected JSON path "#{@path}")
end
alias :failure_message_for_should :failure_message

def failure_message_for_should_not
def failure_message_when_negated
%(Expected no JSON path "#{@path}")
end
alias :failure_message_for_should_not :failure_message_when_negated

def description
%(have JSON path "#{@path}")
Expand Down
6 changes: 4 additions & 2 deletions lib/json_spec/matchers/have_json_size.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ def at_path(path)
self
end

def failure_message_for_should
def failure_message
message_with_path("Expected JSON value size to be #{@expected}, got #{@actual}")
end
alias :failure_message_for_should :failure_message

def failure_message_for_should_not
def failure_message_when_negated
message_with_path("Expected JSON value size to not be #{@expected}, got #{@actual}")
end
alias :failure_message_for_should_not :failure_message_when_negated

def description
message_with_path(%(have JSON size "#{@expected}"))
Expand Down
6 changes: 4 additions & 2 deletions lib/json_spec/matchers/have_json_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ def at_path(path)
self
end

def failure_message_for_should
def failure_message
message_with_path("Expected JSON value type to be #{@classes.join(", ")}, got #{@ruby.class}")
end
alias :failure_message_for_should :failure_message

def failure_message_for_should_not
def failure_message_when_negated
message_with_path("Expected JSON value type to not be #{@classes.join(", ")}, got #{@ruby.class}")
end
alias :failure_message_for_should_not :failure_message_when_negated

def description
message_with_path(%(have JSON type "#{@classes.join(", ")}"))
Expand Down
6 changes: 4 additions & 2 deletions lib/json_spec/matchers/include_json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ def including(*keys)
self
end

def failure_message_for_should
def failure_message
message_with_path("Expected included JSON")
end
alias :failure_message_for_should :failure_message

def failure_message_for_should_not
def failure_message_when_negated
message_with_path("Expected excluded JSON")
end
alias :failure_message_for_should_not :failure_message_when_negated

def description
message_with_path("include JSON")
Expand Down
10 changes: 6 additions & 4 deletions spec/json_spec/matchers/have_json_size_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,18 @@
%({"one":[1,2,3]}).should have_json_size(3).at_path("one")
end

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

it "provides a failure message for should not" do
it "provides a failure message for negation" do
matcher = have_json_size(3)
matcher.matches?(%([1,2,3]))
matcher.failure_message_for_should_not.should == "Expected JSON value size to not be 3, got 3"
matcher.failure_message_when_negated.should == "Expected JSON value size to not be 3, got 3"
matcher.failure_message_for_should_not.should == "Expected JSON value size to not be 3, got 3" # RSpec 2 interface
end

it "provides a description message" do
Expand Down
10 changes: 6 additions & 4 deletions spec/json_spec/matchers/have_json_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,18 @@
%(10.0).should have_json_type(Numeric)
end

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

it "provides a failure message for should not" do
it "provides a failure message for negation" do
matcher = have_json_type(Numeric)
matcher.matches?(%(10))
matcher.failure_message_for_should_not.should == "Expected JSON value type to not be Numeric, got Fixnum"
matcher.failure_message_when_negated.should == "Expected JSON value type to not be Numeric, got Fixnum"
matcher.failure_message_for_should_not.should == "Expected JSON value type to not be Numeric, got Fixnum" # RSpec 2 interface
end

it "provides a description message" do
Expand Down