"assign" to variable in view seems to give nil object

Hello,

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’]

render '/a_details/index.html.erb'

response.should have_tag("ul") do
  with_tag("li") do
    with_tag("div", "Name")
    with_tag("div", "Details")
  end
end

end
end

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>
14:
15: <% @a_details.each do |shoe_detail| %>
16:   <tr>
17:     <td><%=h a_detail.brand %></td>
18:     <td><%=h a_detail.city_photo %></td>

app/views/a_details/index.html.erb:15
haml (3.0.18) rails/./lib/haml/helpers/action_view_mods.rb:13:in

render_without_mock_proxy' spec/views/a_details/index_spec.rb:8 rspec (1.3.0) lib/spec/example/example_methods.rb:40:ininstance_eval’
rspec (1.3.0) lib/spec/example/example_methods.rb:40:in execute' /opt/local/lib/ruby/1.8/timeout.rb:53:intimeout’

On Sep 29, 2010, at 2:56 PM, poseid wrote:

assign[:a_details] = [‘test’]
This looks like Rails-2/RSpec-1. If that’s correct, then you want to use
“assigns” instead of “assign”.

HTH,
David

Thanks, David.
You are right, there could be a clash of versions.

Now, “assigns” gives:

index_spec.rb:6: undefined local variable or method assigns' for Spec::Rails::Example::ViewExampleGroup::Subclass_1:Class (NameError) from /opt/local/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/example/ example_group_methods.rb:183:inmodule_eval’
from /opt/local/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/example/
example_group_methods.rb:183:in subclass' from /opt/local/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/example/ example_group_methods.rb:55:indescribe’
from /opt/local/lib/ruby/gems/1.8/gems/rspec-1.3.0/lib/spec/example/
example_group_factory.rb:31:in `create_example_group’

Maybe I shall start with another clean rails project?

Thanks for your help,
Patrick

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs