lib/rspec/rails/example/widget_example_group.rb in rspec-apotomo-0.9.1 vs lib/rspec/rails/example/widget_example_group.rb in rspec-apotomo-0.9.2
- old
+ new
@@ -1,33 +1,67 @@
require 'apotomo'
require 'apotomo/test_case'
+require 'rspec/rails'
module RSpec::Rails
module WidgetExampleGroup
extend ActiveSupport::Concern
+ include RSpec::Rails::RailsExampleGroup
+
include Apotomo::TestCase::TestMethods
-
+
+ if defined?(Webrat)
+ include Webrat::Matchers
+ include Webrat::Methods
+ end
+
+ if defined?(Capybara)
+ begin
+ include Capybara::DSL
+ rescue NameError
+ include Capybara
+ end
+
+ # Overwrite to wrap render_widget into a Capybara custom string with a
+ # lot of matchers.
+ #
+ # Read more at:
+ #
+ # The Capybara.string method documentation:
+ # - http://rubydoc.info/github/jnicklas/capybara/master/Capybara#string-class_method
+ #
+ # Return value is an instance of Capybara::Node::Simple
+ # - http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Node/Simple
+ #
+ # That expose all the methods from the following capybara modules:
+ # - http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Node/Matchers
+ # - http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Node/Finders
+ def render_widget(*args)
+ @last_invoke = Capybara.string super
+ end
+ end
+
included do
before do
- @parent_controller = Class.new(ActionController::Base).new
- @parent_controller.instance_eval do
- extend Apotomo::Rails::ControllerMethods
- def controller_path; 'barn'; end
+ setup # defined in Apotomo::TestCase.
+ @routes = ::Rails.application.routes
+ ActionController::Base.allow_forgery_protection = false
+ @controller.request = ::ActionController::TestRequest.new
+ @controller.class_eval do
+ include Rails.application.routes.url_helpers
end
-
- @parent_controller.request = ::ActionController::TestRequest.new
end
+
+ subject { controller }
end
-
-
+
module InstanceMethods
- # TODO documentation
- def response
+ def rendered
@last_invoke
end
- attr_reader :parent_controller
+ attr_reader :controller, :routes
include ::Apotomo::WidgetShortcuts
end
end
end