Class: Cell::TestCase
- Inherits:
-
ActiveSupport::TestCase
- Object
- ActiveSupport::TestCase
- Cell::TestCase
- Extended by:
- ActionController::TestCase::Behavior::ClassMethods
- Includes:
- ActionDispatch::Assertions::SelectorAssertions, ActiveSupport::Testing::ConstantLookup, 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
statewith 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, CommonTestMethods, TestMethods
Instance Attribute Summary
Attributes included from TestMethods
#last_invoke, #subject_cell, #view_assigns
Class Method Summary collapse
-
.determine_default_controller_class(name) ⇒ Object
FIXME: fix that in Rails 4.x.
Instance Method Summary collapse
Methods included from AssertSelect
#assert_select, #assert_selector
Methods included from TestMethods
Methods included from CommonTestMethods
#extract_state_ivars_for, #setup
Class Method Details
.determine_default_controller_class(name) ⇒ Object
FIXME: fix that in Rails 4.x.
155 156 157 158 159 |
# File 'lib/cell/test_case.rb', line 155 def self.determine_default_controller_class(name) # FIXME: fix that in Rails 4.x. determine_constant_from_test_name(name) do |constant| Class === constant #&& constant < ActionController::Metal end end |
Instance Method Details
#invoke(state, *args) ⇒ Object
149 150 151 |
# File 'lib/cell/test_case.rb', line 149 def invoke(state, *args) @last_invoke = self.class.controller_class.new(@controller).render_state(state, *args) end |