[rspec-users] "assign" to variable in view seems to give nil object
dchelimsky at gmail.com
Thu Sep 30 08:12:11 EDT 2010
On Sep 29, 2010, at 2:56 PM, poseid wrote:
> I am doing my first steps with rspec and did the following observation.
> I wanted to write a spec for a standard scaffold index view.
> Now, my view spec looks like:
> describe "/a_details/index.html.erb" do
> it "should list all the details of as in an unordered list" do
> assign[:a_details] = ['test']
This looks like Rails-2/RSpec-1. If that's correct, then you want to use "assigns" instead of "assign".
> render '/a_details/index.html.erb'
> response.should have_tag("ul") do
> with_tag("li") do
> with_tag("div", "Name")
> with_tag("div", "Details")
> Can someone show me a direction and/or has a solution to this ?
> When I run this I get:
> ActionView::TemplateError in '/a_details/index.html.erb should list
> all the details of shoes in an unordered list'
> You have a nil object when you didn't expect it!
> You might have expected an instance of Array.
> The error occurred while evaluating nil.each
> On line #15 of app/views/shoe_details/index.html.erb
> 12: <th>Photo quality</th>
> 13: </tr>
> 15: <% @a_details.each do |shoe_detail| %>
> 16: <tr>
> 17: <td><%=h a_detail.brand %></td>
> 18: <td><%=h a_detail.city_photo %></td>
> haml (3.0.18) rails/./lib/haml/helpers/action_view_mods.rb:13:in
> rspec (1.3.0) lib/spec/example/example_methods.rb:40:in
> rspec (1.3.0) lib/spec/example/example_methods.rb:40:in `execute'
> /opt/local/lib/ruby/1.8/timeout.rb:53:in `timeout'
More information about the rspec-users