Module: RSpec::Rails::ViewExampleGroup::InstanceMethods
- Defined in:
- lib/rspec/rails/example/view_example_group.rb
Instance Method Summary collapse
-
#params ⇒ Object
Provides access to the params hash that will be available within the view:.
-
#render(options = {}, local_assigns = {}, &block) ⇒ Object
:call-seq: render render(:template => “widgets/new.html.erb”) render(=> “widgets/widget.html.erb”, locals …) render(=> “widgets/widget.html.erb”, locals …) do …
-
#response ⇒ Object
Deprecated.
-
#stub_template(hash) ⇒ Object
Simulates the presence of a template on the file system by adding a Rails’ FixtureResolver to the front of the view_paths list.
-
#template ⇒ Object
Deprecated.
-
#view ⇒ Object
The instance of ActionView::Base that is used to render the template.
Instance Method Details
#params ⇒ Object
Provides access to the params hash that will be available within the view:
params[:foo] = 'bar'
103 104 105 |
# File 'lib/rspec/rails/example/view_example_group.rb', line 103 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
67 68 69 70 |
# File 'lib/rspec/rails/example/view_example_group.rb', line 67 def render(={}, local_assigns={}, &block) = {:template => _default_file_to_render} if Hash === and .empty? super(, local_assigns, &block) end |
#response ⇒ Object
Deprecated. Use rendered
instead.
114 115 116 117 |
# File 'lib/rspec/rails/example/view_example_group.rb', line 114 def response RSpec.deprecate("response", "rendered") rendered end |
#stub_template(hash) ⇒ Object
Simulates the presence of a template on the file system by adding a Rails’ FixtureResolver to the front of the view_paths list. Designed to help isolate view examples from partials rendered by the view template that is the subject of the example.
Example
stub_template("widgets/_widget.html.erb" => "This content.")
95 96 97 |
# File 'lib/rspec/rails/example/view_example_group.rb', line 95 def stub_template(hash) view.view_paths.unshift(ActionView::FixtureResolver.new(hash)) end |
#template ⇒ Object
Deprecated. Use view
instead.
108 109 110 111 |
# File 'lib/rspec/rails/example/view_example_group.rb', line 108 def template RSpec.deprecate("template","view") view end |
#view ⇒ Object
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
83 84 85 |
# File 'lib/rspec/rails/example/view_example_group.rb', line 83 def view _view end |