Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Update for RSpec 3 beta 2 #71

Merged
merged 4 commits into from

6 participants

@skalee
  1. Support new matcher interface.

    Do you prefer alias or alias_method? I'm using alias because it's RDoc-friendly and those matchers are not likely to be subclassed, but I can change to alias_method if you want.

  2. Explicitly enable both expectation syntaxes.

    Both fashions something.should be_like_this and expect(something).to be_like_this are used in tests so I enabled them. As in above, I can change it if you want to gradually force one or another and warnings seem helpful.

skalee added some commits
@skalee skalee 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
67a3369
@skalee skalee Explicitly enable both RSpec expectation styles 54613f7
@skalee skalee Bump RSpec 3 test dependency to freshest beta 2cc577c
@skalee

BTW how about setting RSpec to fail in case of deprecation warnings? If you don't need them to promote one syntax or another, they would be very helpful. Some pull requests (like #64) were created before beta 2 and they don't honor most recent deprecations.

@skalee

Dependencies updated. Could anyone with an active real-life project confirm that it works well with stable RSpec 3? Tests indicate no problems.

@dredozubov

@laserlemon @skalee looks ok, can we merge it?

@mscottford

I can confirm that this is working.

@ToMoCoop

Can someone merge this PR please?

@laserlemon laserlemon merged commit 4aa659c into collectiveidea:master
@laserlemon
Owner

Version 1.1.2 released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 25, 2014
  1. @skalee

    Update matcher protocol for RSpec 3

    skalee authored
    "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
  2. @skalee
  3. @skalee
Commits on Jun 10, 2014
  1. @skalee
This page is out of date. Refresh to see the latest.
View
2  gemfiles/rspec3.gemfile
@@ -4,6 +4,6 @@ gemspec :path => '..'
group :test do
gem "cucumber", "~> 1.1", ">= 1.1.1"
- gem "rspec", ">= 3.0.0.beta1", "< 4.0"
+ gem "rspec", "~> 3.0"
gem "rake", "~> 10.0"
end
View
6 lib/json_spec/matchers/be_json_eql.rb
@@ -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")
View
6 lib/json_spec/matchers/have_json_path.rb
@@ -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}")
View
6 lib/json_spec/matchers/have_json_size.rb
@@ -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}"))
View
6 lib/json_spec/matchers/have_json_type.rb
@@ -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(", ")}"))
View
6 lib/json_spec/matchers/include_json.rb
@@ -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")
View
10 spec/json_spec/matchers/have_json_size_spec.rb
@@ -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
View
10 spec/json_spec/matchers/have_json_type_spec.rb
@@ -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
View
7 spec/spec_helper.rb
@@ -4,6 +4,13 @@
config.before do
JsonSpec.reset
end
+
+ config.expect_with :rspec do |c|
+ c.syntax = [:should, :expect]
+ end
+ config.mock_with :rspec do |c|
+ c.syntax = [:should, :expect]
+ end
end
def files_path
Something went wrong with that request. Please try again.