Module: Apotomo::TestCase::TestMethods

Extended by:
ActiveSupport::Concern
Includes:
Cell::TestCase::CommonTestMethods
Included in:
Apotomo::TestCase
Defined in:
lib/apotomo/test_case.rb

Overview

Generic test methods to be used in Test::Unit, RSpec, etc.

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#view_assignsObject (readonly)

Returns the value of attribute view_assigns


39
40
41
# File 'lib/apotomo/test_case.rb', line 39

def view_assigns
  @view_assigns
end

Instance Method Details

#parent_controllerObject


81
82
83
# File 'lib/apotomo/test_case.rb', line 81

def parent_controller
  @controller
end

#render_widget(*args) ⇒ Object

Renders the widget name.


53
54
55
56
57
58
59
60
# File 'lib/apotomo/test_case.rb', line 53

def render_widget(*args)
  @view_assigns = extract_state_ivars_for(root[args.first]) do
    @last_invoke = root.render_widget(*args)
  end
  cleanup_assigns!(@view_assigns)

  @last_invoke
end

#rootObject

Returns the widget tree from TestCase.has_widgets.


74
75
76
77
78
79
# File 'lib/apotomo/test_case.rb', line 74

def root
  blk = self.class.has_widgets_blocks or raise "Please setup a widget tree using has_widgets()"
  @root ||= Apotomo::Widget.new(parent_controller, "root").tap do |root|
     self.instance_exec(root, &blk)
  end
end

#setupObject


41
42
43
44
45
46
47
48
49
50
# File 'lib/apotomo/test_case.rb', line 41

def setup
  super # defined in Cell::TestCase::CommonTestMethods.

  @controller.instance_eval do
    def controller_path
      'barn'
    end
  end
  @controller.extend Apotomo::Rails::ControllerMethods
end

#trigger(type, source, options = {}) ⇒ Object

Triggers an event of type. You have to pass the source as second options.

Example:

trigger :submit, :comments

67
68
69
70
71
# File 'lib/apotomo/test_case.rb', line 67

def trigger(type, source, options={})
  source = root.find_widget(source)
  source.fire(type, options)
  root.page_updates
end