Class: Rails::AddOns::Shoulda::Matchers::ImplementIndexActionMatcher

Inherits:
Object
  • Object
show all
Includes:
RSpec::Matchers
Defined in:
lib/rails/add_ons/shoulda/matchers/implement_index_action_matcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(spec) ⇒ ImplementIndexActionMatcher

Returns a new instance of ImplementIndexActionMatcher.



20
21
22
# File 'lib/rails/add_ons/shoulda/matchers/implement_index_action_matcher.rb', line 20

def initialize(spec)
  @spec = spec
end

Instance Method Details

#descriptionObject



58
59
60
# File 'lib/rails/add_ons/shoulda/matchers/implement_index_action_matcher.rb', line 58

def description
  "expose index action on #{@base_path}"
end

#failure_messageObject



48
49
50
# File 'lib/rails/add_ons/shoulda/matchers/implement_index_action_matcher.rb', line 48

def failure_message
  "Should expose index action on #{@base_path}. Error: #{@error}"
end

#failure_message_when_negatedObject Also known as: negative_failure_message



52
53
54
# File 'lib/rails/add_ons/shoulda/matchers/implement_index_action_matcher.rb', line 52

def failure_message_when_negated
  "Should not expose index action on #{@base_path}. Error: #{@error}"
end

#has_correct_current_pathObject



39
40
41
42
43
44
45
46
# File 'lib/rails/add_ons/shoulda/matchers/implement_index_action_matcher.rb', line 39

def has_correct_current_path
  if @spec.current_path == @base_path
    true
  else
    @error = "Wrong current path [#{@spec.current_path}] instead of [#{@base_path}]"
    false
  end
end

#has_correct_status_codeObject



30
31
32
33
34
35
36
37
# File 'lib/rails/add_ons/shoulda/matchers/implement_index_action_matcher.rb', line 30

def has_correct_status_code
  if @spec.status_code == 200
    true
  else
    @error = "Wrong status code [#{@spec.status_code}] instead of [200]"
    false
  end
end

#matches?(base_path) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
27
28
# File 'lib/rails/add_ons/shoulda/matchers/implement_index_action_matcher.rb', line 24

def matches?(base_path)
  @base_path = base_path
  @spec.visit(@base_path)
  has_correct_status_code && has_correct_current_path
end