Class: Rails::AddOns::Shoulda::Matchers::ImplementShowActionMatcher

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

Instance Method Summary collapse

Constructor Details

#initialize(spec) ⇒ ImplementShowActionMatcher


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

def initialize(spec)
  @spec = spec
end

Instance Method Details

#descriptionObject


71
72
73
# File 'lib/rails/add_ons/shoulda/matchers/implement_show_action_matcher.rb', line 71

def description
  "expose show action on #{@expected_path}"
end

#failure_messageObject


61
62
63
# File 'lib/rails/add_ons/shoulda/matchers/implement_show_action_matcher.rb', line 61

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

#failure_message_when_negatedObject Also known as: negative_failure_message


65
66
67
# File 'lib/rails/add_ons/shoulda/matchers/implement_show_action_matcher.rb', line 65

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

#for(resource) ⇒ Object

Resource that will be updated


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

def for(resource)
  @resource = resource
  self
end

#has_correct_current_pathObject


52
53
54
55
56
57
58
59
# File 'lib/rails/add_ons/shoulda/matchers/implement_show_action_matcher.rb', line 52

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

#has_correct_status_codeObject


43
44
45
46
47
48
49
50
# File 'lib/rails/add_ons/shoulda/matchers/implement_show_action_matcher.rb', line 43

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

#idObject


30
31
32
# File 'lib/rails/add_ons/shoulda/matchers/implement_show_action_matcher.rb', line 30

def id
  @resource.to_param
end

#matches?(base_path) ⇒ Boolean


34
35
36
37
38
39
40
41
# File 'lib/rails/add_ons/shoulda/matchers/implement_show_action_matcher.rb', line 34

def matches?(base_path)
  @base_path = @spec.class.name.split('::')[0..2].join('::').constantize.description
  # @base_path     = base_path
  @expected_path = "#{@base_path}/#{id}"

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