Rspec test cannot be passed when render partial in layout


#1

I have a problem stuck me couples of days, could anyone help me?
Thanks very much.
The problem is that rspec test cannot be passed when the layout
contains :partial,
once i removed the :partial, the rspec test passed successfully. I
could not find out the reason.
Below is my code:
application.html.erb

<%= render :partial => 'shared/header' %>
<%= yield %>
<%= render :partial => 'shared/footer' %>

users_controller_spec.rb
describe UsersController do
describe “Requesting /forgot_password using GET” do
it “should be successful” do
get :forgot_password
end
end
end


#2

would be nice to know if your page renders correctly when you access
it with your browser. also post the code of the partial that’s causing
the error and of course the error itself. what’s respec’s output?


#3

and each error has same informationm which is “wrong number of
arguments (3 for 1)”
which method is called with 3 arguments instead of 1?
is there anymore information you can give us?


#4

i just do not know which method is called with 3 arguments instead of
1, so i could not solve the problem.
and i pasted the relevant code below:
routes.rb:

map.resources :users, :member => { :suspend => :get, :unsuspend
=> :get }

users_controller.rb:

render new.rhtml

def new
@user = User.new
end

users_controller_spec.rb:

describe “named routing” do
before(:each) do
get :new
end
it “should route new_user_path() to /users/new” do
new_user_path().should == “/users/new”
end
end

new.html.erb:

Sign up as a new user

<% @user.password = @user.password_confirmation = nil %>

<% if flash[:error] %>
<%= flash[:error] %>
<% end %> <% form_for :user, :url => users_path, :html => {:class => 'bigform'} do |f| -%>
<%= label_tag 'login' %> <%= f.text_field :login, :class=>"text" %><%= error_message_on "user", "login" %>
  <div class="clearfix"><%= label_tag 'email' %>
  <%= f.text_field :email, :class=>"text" %>
  <%= error_message_on "user", "email" %></div>

  <div class="clearfix"><%= label_tag 'password' %>
  <%= f.password_field :password, :class=>"text" %>
  <%= error_message_on "user", "password" %></div>

  <div class="clearfix"><%= label_tag 'password_confirmation',

‘Confirm Password’ %>
<%= f.password_field :password_confirmation, :class=>“text” %>
<%= error_message_on “user”, “password_confirmation” %>



<%= submit_tag ‘Sign up’ %>

<% end -%>

The error is:
ActionView::TemplateError in ‘UsersController named routing should
route new_user_path() to /users/new’
wrong number of arguments (3 for 1)

PS: my rails version is 2.2, is there any more information needed?


#5

it’s hard to say what wenbt wrong. most likely you forgot to put a
closing bracket somewhere or sth similar. i’d try to set a debugger
into that test and go through it step by step (or better ‘next’ by
‘next’ g) until you can nail down which method fails.


#6

Thanks for your replying.
the page render correctly since i would visit it via browser, and it
works all right.
in fact, there is nothing special in my partial, i pasted it below:

_footer.html.erb:

and each error has same informationm which is “wrong number of
arguments (3 for 1)”


#7

i just do not know which method is called with 3 arguments instead of
1, so i could not solve the problem.
and i pasted the relevant code below:
routes.rb:

map.resources :users, :member => { :suspend => :get, :unsuspend
=> :get }

users_controller.rb:

render new.rhtml

def new
@user = User.new
end

users_controller_spec.rb:

describe “named routing” do
before(:each) do
get :new
end
it “should route new_user_path() to /users/new” do
new_user_path().should == “/users/new”
end
end

new.html.erb:

Sign up as a new user

<% @user.password = @user.password_confirmation = nil %>

<% if flash[:error] %>
<%= flash[:error] %>
<% end %> <% form_for :user, :url => users_path, :html => {:class => 'bigform'} do |f| -%>
<%= label_tag 'login' %> <%= f.text_field :login, :class=>"text" %><%= error_message_on "user", "login" %>
  <div class="clearfix"><%= label_tag 'email' %>
  <%= f.text_field :email, :class=>"text" %>
  <%= error_message_on "user", "email" %></div>

  <div class="clearfix"><%= label_tag 'password' %>
  <%= f.password_field :password, :class=>"text" %>
  <%= error_message_on "user", "password" %></div>

  <div class="clearfix"><%= label_tag 'password_confirmation',

‘Confirm Password’ %>
<%= f.password_field :password_confirmation, :class=>“text” %>
<%= error_message_on “user”, “password_confirmation” %>



<%= submit_tag ‘Sign up’ %>

<% end -%>

The error is:
ActionView::TemplateError in ‘UsersController named routing should
route new_user_path() to /users/new’
wrong number of arguments (3 for 1)

PS: my rails version is 2.2, is there any more information needed?


#8

thank you very much and i am going to debug to find out the source
problem