Module: Cell::TestCase::TestMethods

Includes:
CommonTestMethods
Included in:
Cell::TestCase
Defined in:
lib/cell/test_case.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CommonTestMethods

#extract_state_ivars_for, #setup

Instance Attribute Details

#last_invokeObject (readonly)

Returns the value of attribute last_invoke



89
90
91
# File 'lib/cell/test_case.rb', line 89

def last_invoke
  @last_invoke
end

#subject_cellObject (readonly)

Returns the value of attribute subject_cell



89
90
91
# File 'lib/cell/test_case.rb', line 89

def subject_cell
  @subject_cell
end

#view_assignsObject (readonly)

Returns the value of attribute view_assigns



89
90
91
# File 'lib/cell/test_case.rb', line 89

def view_assigns
  @view_assigns
end

Instance Method Details

#cell(name, *args, &block) ⇒ Object

Builds an instance of nameCell for unit testing. Passes the optional block to cell.instance_eval.

Example:

assert_equal "Doo Dumm Dumm..." cell(:bassist).play


112
113
114
115
116
# File 'lib/cell/test_case.rb', line 112

def cell(name, *args, &block)
  Cell::Rails.create_cell_for(name, @controller, *args).tap do |cell|
    cell.instance_eval &block if block_given?
  end
end

#in_view(cell_class, &block) ⇒ Object

Execute the passed block in a real view context of cell_class. Usually you'd test helpers here.

Example:

assert_equal("<h1>Modularity rocks.</h1>", in_view do content_tag(:h1, "Modularity rocks."))


124
125
126
127
128
# File 'lib/cell/test_case.rb', line 124

def in_view(cell_class, &block)
  subject = cell(cell_class)
  setup_test_states_in(subject) # add #in_view to subject cell.
  subject.render_state(:in_view, block)
end

#render_cell(name, state, *args) ⇒ Object

Use this for functional tests of your application cells.

Example:

should "spit out a h1 title" do
  html = render_cell(:news, :latest)
  assert_select html, "h1", "The latest and greatest!"


97
98
99
100
101
102
103
104
105
# File 'lib/cell/test_case.rb', line 97

def render_cell(name, state, *args)
  # DISCUSS: should we allow passing a block here, just as in controllers?
  @subject_cell = ::Cell::Rails.create_cell_for(name, @controller, *args)
  @view_assigns = extract_state_ivars_for(@subject_cell) do
    @last_invoke = @subject_cell.render_state(state, *args)
  end

  @last_invoke
end