Skip to content

Commit

Permalink
Merge pull request #17 from ahmet/master
Browse files Browse the repository at this point in the history
RSpec 3 compatibility
  • Loading branch information
tomas-stefano committed Apr 24, 2014
2 parents 29219c9 + 3aa1ebd commit 7740468
Show file tree
Hide file tree
Showing 14 changed files with 80 additions and 37 deletions.
2 changes: 1 addition & 1 deletion lib/api_matchers/headers/base.rb
Expand Up @@ -29,4 +29,4 @@ def expected_content_type
end
end
end
end
end
10 changes: 7 additions & 3 deletions lib/api_matchers/headers/be_json.rb
Expand Up @@ -5,13 +5,17 @@ def expected_content_type
'application/json; charset=utf-8'
end

def failure_message_for_should
def failure_message
%Q{expected a JSON response with '#{expected_content_type}'. Got: '#{content_type_response}'.}
end

def failure_message_for_should_not
def failure_message_when_negated
%Q{expected to not be a JSON response. Got: '#{expected_content_type}'.}
end

# RSpec 2 compatibility:
alias_method :failure_message_for_should, :failure_message
alias_method :failure_message_for_should_not, :failure_message_when_negated
end
end
end
end
10 changes: 7 additions & 3 deletions lib/api_matchers/headers/be_xml.rb
Expand Up @@ -5,13 +5,17 @@ def expected_content_type
'application/xml; charset=utf-8'
end

def failure_message_for_should
def failure_message
%Q{expected a XML response with '#{expected_content_type}'. Got: '#{content_type_response}'.}
end

def failure_message_for_should_not
def failure_message_when_negated
%Q{expected to not be a XML response. Got: '#{expected_content_type}'.}
end

# RSpec 2 compatibility:
alias_method :failure_message_for_should, :failure_message
alias_method :failure_message_for_should_not, :failure_message_when_negated
end
end
end
end
2 changes: 1 addition & 1 deletion lib/api_matchers/http_status_code/base.rb
Expand Up @@ -29,4 +29,4 @@ def find_http_status_code(actual)
end
end
end
end
end
10 changes: 7 additions & 3 deletions lib/api_matchers/http_status_code/be_bad_request.rb
Expand Up @@ -5,13 +5,17 @@ def expected_status_code
400
end

def failure_message_for_should
def failure_message
%Q{expected that '#{@http_status_code}' to be a Bad Request with the status '400'.}
end

def failure_message_for_should_not
def failure_message_when_negated
%Q{expected that '#{@http_status_code}' to NOT be a Bad Request with the status '400'.}
end

# RSpec 2 compatibility:
alias_method :failure_message_for_should, :failure_message
alias_method :failure_message_for_should_not, :failure_message_when_negated
end
end
end
end
10 changes: 7 additions & 3 deletions lib/api_matchers/http_status_code/be_internal_server_error.rb
Expand Up @@ -5,13 +5,17 @@ def expected_status_code
500
end

def failure_message_for_should
def failure_message
%Q{expected that '#{@http_status_code}' to be Internal Server Error with the status '500'.}
end

def failure_message_for_should_not
def failure_message_when_negated
%Q{expected that '#{@http_status_code}' to NOT be Internal Server Error.}
end

# RSpec 2 compatibility:
alias_method :failure_message_for_should, :failure_message
alias_method :failure_message_for_should_not, :failure_message_when_negated
end
end
end
end
10 changes: 7 additions & 3 deletions lib/api_matchers/http_status_code/be_not_found.rb
Expand Up @@ -5,13 +5,17 @@ def expected_status_code
404
end

def failure_message_for_should
def failure_message
%Q{expected that '#{@http_status_code}' to be Not Found with the status '404'.}
end

def failure_message_for_should_not
def failure_message_when_negated
%Q{expected that '#{@http_status_code}' to NOT be Not Found with the status '404'.}
end

# RSpec 2 compatibility:
alias_method :failure_message_for_should, :failure_message
alias_method :failure_message_for_should_not, :failure_message_when_negated
end
end
end
end
10 changes: 7 additions & 3 deletions lib/api_matchers/http_status_code/be_ok.rb
Expand Up @@ -5,13 +5,17 @@ def expected_status_code
200
end

def failure_message_for_should
def failure_message
%Q{expected that '#{@http_status_code}' to be ok with the status '200'.}
end

def failure_message_for_should_not
def failure_message_when_negated
%Q{expected that '#{@http_status_code}' to NOT be ok with the status '200'.}
end

# RSpec 2 compatibility:
alias_method :failure_message_for_should, :failure_message
alias_method :failure_message_for_should_not, :failure_message_when_negated
end
end
end
end
10 changes: 7 additions & 3 deletions lib/api_matchers/http_status_code/be_unauthorized.rb
Expand Up @@ -5,13 +5,17 @@ def expected_status_code
401
end

def failure_message_for_should
def failure_message
%Q{expected that '#{@http_status_code}' to be Unauthorized with the status '401'.}
end

def failure_message_for_should_not
def failure_message_when_negated
%Q{expected that '#{@http_status_code}' to NOT be Unauthorized.}
end

# RSpec 2 compatibility:
alias_method :failure_message_for_should, :failure_message
alias_method :failure_message_for_should_not, :failure_message_when_negated
end
end
end
end
10 changes: 7 additions & 3 deletions lib/api_matchers/http_status_code/be_unprocessable_entity.rb
Expand Up @@ -5,13 +5,17 @@ def expected_status_code
422
end

def failure_message_for_should
def failure_message
%Q{expected that '#{@http_status_code}' to be Unprocessable entity with the status '#{expected_status_code}'.}
end

def failure_message_for_should_not
def failure_message_when_negated
%Q{expected that '#{@http_status_code}' to NOT be Unprocessable entity with the status '#{expected_status_code}'.}
end

# RSpec 2 compatibility:
alias_method :failure_message_for_should, :failure_message
alias_method :failure_message_for_should_not, :failure_message_when_negated
end
end
end
end
10 changes: 7 additions & 3 deletions lib/api_matchers/http_status_code/create_resource.rb
Expand Up @@ -5,13 +5,17 @@ def expected_status_code
201
end

def failure_message_for_should
def failure_message
%Q{expected that '#{@http_status_code}' to be Created Resource with the status '201'.}
end

def failure_message_for_should_not
def failure_message_when_negated
%Q{expected that '#{@http_status_code}' to NOT be Created Resource.}
end

# RSpec 2 compatibility:
alias_method :failure_message_for_should, :failure_message
alias_method :failure_message_for_should_not, :failure_message_when_negated
end
end
end
end
8 changes: 6 additions & 2 deletions lib/api_matchers/response_body/base.rb
Expand Up @@ -31,14 +31,18 @@ def response_body
end
end

def failure_message_for_should
def failure_message
"expected to have node called: '#{@expected_node}'" << added_message << ". Got: '#{response_body}'"
end

def failure_message_for_should_not
def failure_message_when_negated
"expected to NOT have node called: '#{@expected_node}'" << added_message << ". Got: '#{response_body}'"
end

# RSpec 2 compatibility:
alias_method :failure_message_for_should, :failure_message
alias_method :failure_message_for_should_not, :failure_message_when_negated

def added_message
if @with_value
" with value: '#{@with_value}'"
Expand Down
9 changes: 6 additions & 3 deletions lib/api_matchers/response_body/have_json.rb
Expand Up @@ -14,14 +14,17 @@ def matches?(actual)
@expected_json == json
end

def failure_message_for_should
def failure_message
"expect to have json: '#{response_body}'. Got: '#{json}'."
end

def failure_message_for_should_not
def failure_message_when_negated
"expect to NOT have json: '#{response_body}'."
end

# RSpec 2 compatibility:
alias_method :failure_message_for_should, :failure_message
alias_method :failure_message_for_should_not, :failure_message_when_negated
end
end
end

6 changes: 3 additions & 3 deletions spec/api_matchers/response_body/have_json_node_spec.rb
Expand Up @@ -38,7 +38,7 @@
end

it "pass when the expected key exists with the expected value (as DateTime)" do
now = DateTime.now
now = DateTime.now.to_s
expect({ :date => now }.to_json).to have_json_node(:date).with(now)
end

Expand All @@ -48,7 +48,7 @@
end

it "pass when the expected key exists with the expected value (as Time)" do
now = Time.now
now = Time.now.to_s
expect({ :time => now }.to_json).to have_json_node(:time).with(now)
end

Expand Down Expand Up @@ -275,4 +275,4 @@
}.to fail_with(%Q{expected to have node called: 'bar'. Got: '{"baz":"foo"}'})
end
end
end
end

0 comments on commit 7740468

Please sign in to comment.