Class: PufferPages::Rspec::Matchers::RenderPage

Inherits:
RSpec::Matchers::BuiltIn::BaseMatcher
  • Object
show all
Defined in:
lib/puffer_pages/rspec/matchers/render_page.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scope, page = nil) ⇒ RenderPage

Returns a new instance of RenderPage.



7
8
9
10
11
12
# File 'lib/puffer_pages/rspec/matchers/render_page.rb', line 7

def initialize scope, page = nil
  @scope = scope
  @page = page
  @page = PufferPages::Page.find_page(page) if page.is_a?(String)
  @drops ||= { values: {}, names: [], manual: [] }
end

Instance Attribute Details

#dropsObject (readonly)

Returns the value of attribute drops.



5
6
7
# File 'lib/puffer_pages/rspec/matchers/render_page.rb', line 5

def drops
  @drops
end

#pageObject (readonly)

Returns the value of attribute page.



5
6
7
# File 'lib/puffer_pages/rspec/matchers/render_page.rb', line 5

def page
  @page
end

#scopeObject (readonly)

Returns the value of attribute scope.



5
6
7
# File 'lib/puffer_pages/rspec/matchers/render_page.rb', line 5

def scope
  @scope
end

Instance Method Details

#descriptionObject



44
45
46
# File 'lib/puffer_pages/rspec/matchers/render_page.rb', line 44

def description
  "render page #{page_message}"
end

#failure_message_for_shouldObject



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/puffer_pages/rspec/matchers/render_page.rb', line 27

def failure_message_for_should
  message = ''
  message << "expected action to render #{page_message}\n"
  message << "with drops #{drops_message}\n" if with_drops?
  if with_drops? && !drops_conformity
    rendered_drops = scope.puffer_pages_render[rendered_page].first[:drops]
    message << "but available drops are: #{PP.pp rendered_drops, ''}"
  else
    message << "but #{rendered_page ? "`/#{rendered_page.location}`" : 'nothing'} was rendered"
  end
  message
end

#failure_message_for_should_notObject



40
41
42
# File 'lib/puffer_pages/rspec/matchers/render_page.rb', line 40

def failure_message_for_should_not
  "expected action not to render #{page_message} but `/#{rendered_page.location}` was rendered"
end

#matches?(controller_or_request) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
17
18
# File 'lib/puffer_pages/rspec/matchers/render_page.rb', line 14

def matches? controller_or_request
  scope.get :index if controller_or_request.is_a?(ActionController::Base)

  rendered_page && (!with_page? || page_conformity) && (!with_drops? || drops_conformity)
end

#with_drops(*drops, &block) ⇒ Object



20
21
22
23
24
25
# File 'lib/puffer_pages/rspec/matchers/render_page.rb', line 20

def with_drops *drops, &block
  @drops[:values].merge! drops.extract_options!
  @drops[:names].concat(drops.flatten).uniq!
  @drops[:manual].push block if block
  self
end