Skip to content

Commit

Permalink
Fix deprecated matcher method on DenyAccessMatcher
Browse files Browse the repository at this point in the history
`DenyAccessMatcher` used `#negative_failure_message`, which has been
deprecated in favor of the newer RSpec matcher method
`#failure_message_when_negated`. Renamed this instance variable and the
`attr_reader` to remove RSpec 3.0 deprecation warnings when using
`DenyAccessMatcher` in specs.

Added aliases `failure_message_for_should` and
`failure_message_for_should_not` to maintain RSpec 1.2+, < 3.0
compatibility.
  • Loading branch information
geoffharcourt authored and derekprior committed Sep 13, 2014
1 parent e4208f7 commit 663ae99
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions lib/clearance/testing/deny_access_matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ def deny_access(opts = {})
end

class DenyAccessMatcher
attr_reader :failure_message, :negative_failure_message
attr_reader :failure_message, :failure_message_when_negated

def initialize(context, opts)
@context = context
@flash = opts[:flash]
@url = opts[:redirect]

@failure_message = ''
@negative_failure_message = ''
@failure_message_when_negated = ''
end

def description
Expand All @@ -28,6 +28,14 @@ def matches?(controller)
sets_the_flash? && redirects_to_url?
end

def failure_message_for_should
failure_message
end

def failure_message_for_should_not
failure_message_when_negated
end

private

def denied_access_url
Expand Down Expand Up @@ -55,7 +63,8 @@ def redirects_to_url?

begin
@context.send(:assert_redirected_to, @url)
@negative_failure_message << "Didn't expect to redirect to #{@url}."
@failure_message_when_negated <<
"Didn't expect to redirect to #{@url}."
true
rescue Clearance::Testing::AssertionError
@failure_message << "Expected to redirect to #{@url} but did not."
Expand All @@ -68,10 +77,12 @@ def sets_the_flash?
true
else
if flash_notice_value == @flash
@negative_failure_message << "Didn't expect to set the flash to #{@flash}"
@failure_message_when_negated <<
"Didn't expect to set the flash to #{@flash}"
true
else
@failure_message << "Expected the flash to be set to #{@flash} but was #{flash_notice_value}"
@failure_message << "Expected the flash to be set to #{@flash} "\
"but was #{flash_notice_value}"
false
end
end
Expand Down

0 comments on commit 663ae99

Please sign in to comment.