| Class | Spec::Rails::Example::ViewExampleGroup |
| In: |
lib/spec/rails/example/view_example_group.rb
|
| Parent: | FunctionalExampleGroup |
View Examples live in $RAILS_ROOT/spec/views/.
View Specs use Spec::Rails::Example::ViewExampleGroup, which provides access to views without invoking any of your controllers. See Spec::Rails::Expectations::Matchers for information about specific expectations that you can set on views.
describe "login/login" do
before do
render 'login/login'
end
it "should display login form" do
response.should have_tag("form[action=/login]") do
with_tag("input[type=text][name=email]")
with_tag("input[type=password][name=password]")
with_tag("input[type=submit][value=Login]")
end
end
end
Renders a template for a View Spec, which then provides access to the result through the response. Also supports render with :inline, which you can use to spec custom form builders, helpers, etc, in the context of a view.
render('/people/list')
render('/people/list', :helper => MyHelper)
render('/people/list', :helpers => [MyHelper, MyOtherHelper])
render(:partial => '/people/_address')
render(:inline => "<% custom_helper 'argument', 'another argument' %>")
See Spec::Rails::Example::ViewExampleGroup for more information.
# File lib/spec/rails/example/view_example_group.rb, line 98
98: def render(*args)
99: options = Hash === args.last ? args.pop : {}
100: options[:template] = args.first.to_s unless args.empty?
101:
102: set_base_view_path(options)
103: add_helpers(options)
104:
105: assigns[:action_name] = @action_name
106:
107: @request.path_parameters = {
108: :controller => derived_controller_name(options),
109: :action => derived_action_name(options)
110: }
111:
112: defaults = { :layout => false }
113: options = defaults.merge options
114:
115: @controller.send(:params).reverse_merge! @request.parameters
116:
117: @controller.send :initialize_current_url
118:
119: @controller.class.instance_eval %{
120: def controller_path
121: "#{derived_controller_name(options)}"
122: end
123:
124: def controller_name
125: "#{derived_controller_name(options).split('/').last}"
126: end
127: }
128:
129: @controller.send :forget_variables_added_to_assigns
130: @controller.send :render, options
131: @controller.send :process_cleanup
132: end
This provides the template. Use this to set mock expectations for dealing with partials
describe "/person/new" do
it "should use the form partial" do
template.should_receive(:render).with(:partial => 'form')
render "/person/new"
end
end
# File lib/spec/rails/example/view_example_group.rb, line 145
145: def template
146: @controller.template
147: end