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


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


60
61
62
# File 'lib/rails/add_ons/shoulda/matchers/implement_index_action_matcher.rb', line 60

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

#failure_messageObject


50
51
52
# File 'lib/rails/add_ons/shoulda/matchers/implement_index_action_matcher.rb', line 50

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

#failure_message_when_negatedObject Also known as: negative_failure_message


54
55
56
# File 'lib/rails/add_ons/shoulda/matchers/implement_index_action_matcher.rb', line 54

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

#has_correct_current_pathObject


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

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


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

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


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

def matches?(base_path)
  @base_path = @spec.class.name.split('::')[0..2].join('::').constantize.description
  # @base_path     = base_path

  @spec.visit(@base_path)
  has_correct_status_code && has_correct_current_path
end