Module: RSpec::Rails::ViewExampleGroup::InstanceMethods

Defined in:
lib/rspec/rails/example/view_example_group.rb

Instance Method Summary collapse

Instance Method Details

#paramsObject

Provides access to the params hash that will be available within the view:

params[:foo] = 'bar'


92
93
94
# File 'lib/rspec/rails/example/view_example_group.rb', line 92

def params
  controller.params
end

#render(options = {}, local_assigns = {}, &block) ⇒ Object

:call-seq:

render
render(:template => "widgets/new.html.erb")
render({:partial => "widgets/widget.html.erb"}, {... locals ...})
render({:partial => "widgets/widget.html.erb"}, {... locals ...}) do ... end

Delegates to ActionView::Base#render, so see documentation on that for more info.

The only addition is that you can call render with no arguments, and RSpec will pass the top level description to render:

describe "widgets/new.html.erb" do
  it "shows all the widgets" do
    render # => view.render(:file => "widgets/new.html.erb")
    ...
  end
end


68
69
70
71
# File 'lib/rspec/rails/example/view_example_group.rb', line 68

def render(options={}, local_assigns={}, &block)
  options = {:template => _default_file_to_render} if Hash === options and options.empty?
  super(options, local_assigns, &block)
end

#responseObject

Deprecated. Use rendered instead.



103
104
105
106
# File 'lib/rspec/rails/example/view_example_group.rb', line 103

def response
  RSpec.deprecate("response", "rendered")
  rendered
end

#templateObject

Deprecated. Use view instead.



97
98
99
100
# File 'lib/rspec/rails/example/view_example_group.rb', line 97

def template
  RSpec.deprecate("template","view")
  view
end

#viewObject

The instance of ActionView::Base that is used to render the template. Use this before the render call to stub any methods you want to stub on the view:

describe "widgets/new.html.erb" do
  it "shows all the widgets" do
    view.stub(:foo) { "foo" }
    render
    ...
  end
end


84
85
86
# File 'lib/rspec/rails/example/view_example_group.rb', line 84

def view
  _view
end