Class Spec::Rails::Example::ViewExampleGroup
In: vendor/plugins/rspec_on_rails/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.

Example

  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

Methods

render   template  

Public Instance methods

Renders a template for a View Spec, which then provides access to the result through the response.

Examples

  render('/people/list')
  render('/people/list', :helper => MyHelper)
  render('/people/list', :helpers => [MyHelper, MyOtherHelper])
  render(:partial => '/people/_address')

See Spec::Rails::Example::ViewExampleGroup for more information.

[Source]

     # File vendor/plugins/rspec_on_rails/lib/spec/rails/example/view_example_group.rb, line 96
 96:         def render(*args)
 97:           options = Hash === args.last ? args.pop : {}
 98:           options[:template] = args.first.to_s unless args.empty?
 99: 
100:           set_base_view_path(options)
101:           add_helpers(options)
102: 
103:           assigns[:action_name] = @action_name
104: 
105:           @request.path_parameters = {
106:           :controller => derived_controller_name(options),
107:           :action => derived_action_name(options)
108:           }
109: 
110:           defaults = { :layout => false }
111:           options = defaults.merge options
112: 
113:           @controller.instance_variable_set :@params, @request.parameters
114: 
115:           @controller.send :initialize_current_url
116: 
117:           @controller.class.instance_eval %{
118:             def controller_path
119:               "#{derived_controller_name(options)}"
120:             end
121: 
122:             def controller_name
123:               "#{derived_controller_name(options).split('/').last}"
124:             end
125:           }
126: 
127:           @controller.send :forget_variables_added_to_assigns
128:           @controller.send :render, options
129:           @controller.send :process_cleanup
130:         end

This provides the template. Use this to set mock expectations for dealing with partials

Example

  describe "/person/new" do
    it "should use the form partial" do
      template.should_receive(:render).with(:partial => 'form')
      render "/person/new"
    end
  end

[Source]

     # File vendor/plugins/rspec_on_rails/lib/spec/rails/example/view_example_group.rb, line 143
143:         def template
144:           @controller.template
145:         end

[Validate]