Class: PermalinkFu::Spec::Matchers::PermalinkTo

Inherits:
Object
  • Object
show all
Defined in:
lib/permalink_fu/spec/matchers.rb

Instance Method Summary collapse

Constructor Details

#initialize(permalink, to_param = nil) ⇒ PermalinkTo

Returns a new instance of PermalinkTo.



5
6
7
8
# File 'lib/permalink_fu/spec/matchers.rb', line 5

def initialize(permalink, to_param = nil)
  @expected_permalink = permalink
  @expected_to_param = to_param
end

Instance Method Details

#failure_messageObject



16
17
18
19
20
21
22
23
# File 'lib/permalink_fu/spec/matchers.rb', line 16

def failure_message
  message = []

  message << "to permalink to #{@expected_permalink.inspect} (got #{@permalink.inspect})" if @permalink != @expected_permalink
  message << "to generate a URL like #{expected_to_param.inspect} (got #{@to_param.inspect})" if @to_param != expected_to_param
  
  "expected #{message.join(' and ')}"
end

#matches?(target) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
14
# File 'lib/permalink_fu/spec/matchers.rb', line 10

def matches?(target)
  @target = target
  @permalink, @to_param = target.permalink, target.to_param
  @permalink == @expected_permalink && @to_param == expected_to_param
end