Class: Cell::TestCase

Inherits:
ActiveSupport::TestCase
  • Object
show all
Extended by:
ActionController::TestCase::Behavior::ClassMethods
Includes:
ActionDispatch::Assertions::SelectorAssertions, AssertSelect, TestMethods
Defined in:
lib/cell/test_case.rb

Overview

Test your cells.

This class is roughly equal to ActionController::TestCase, exposing the same semantics. It will try to infer the tested cell name from the test name if you use declarative testing. You can also set it with TestCase.tests.

A declarative test would look like

class SellOutTest < Cell::TestCase
  tests ShoppingCartCell

  it "should be rendered nicely" do
    invoke :order_button, :items => @fixture_items

    assert_select "button", "Order now!"
  end

You can also do stuff yourself, like

it "should be rendered even nicer" do
  html = render_cell(:shopping_cart, :order_button, , :items => @fixture_items)
  assert_selector "button", "Order now!", html
end

Or even unit test your cell:

it "should provide #default_items" do
  assert_equal [@item1, @item2], cell(:shopping_cart).default_items
end

Test helpers

Basically, we got these new methods:

invoke

Renders the passed state with your tested cell. You may pass options like in #render_cell.

render_cell

As in your views. Will return the rendered view.

assert_selector

Like #assert_select except that the last argument is the html markup you wanna test.

cell

Gives you a cell instance for unit testing and stuff.

Defined Under Namespace

Modules: AssertSelect, TestMethods

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AssertSelect

#assert_select, #assert_selector

Methods included from TestMethods

#cell, #in_view, #render_cell, #setup

Instance Attribute Details

#last_invokeObject (readonly)

Returns the value of attribute last_invoke.



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

def last_invoke
  @last_invoke
end

Instance Method Details

#invoke(state, *args) ⇒ Object



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

def invoke(state, *args)
  @last_invoke = self.class.controller_class.new(@controller, *args).render_state(state)
end