Module: Cell::TestCase::TestMethods

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

Instance Method Summary collapse

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 "Banks kill planet!" cell(:news, :topic => :terror).latest_headline


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

def cell(name, *args, &block)
  cell = ::Cell::Base.create_cell_for(@controller, name, *args)
  cell.instance_eval &block if block_given?
  cell
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."))


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

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

#render_cell(*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_selekt html, "h1", "The latest and greatest!"


78
79
80
# File 'lib/cell/test_case.rb', line 78

def render_cell(*args)
  @controller.render_cell(*args)
end

#setupObject



63
64
65
66
67
68
69
70
# File 'lib/cell/test_case.rb', line 63

def setup
  @controller = Class.new(ActionController::Base).new
  @request    = ::ActionController::TestRequest.new
  @response   = ::ActionController::TestResponse.new
  @controller.request = @request
  @controller.response = @response
  @controller.params = {}
end