Forum: Ruby on Rails rspec test cannot be passed when render partial in layout

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
zerogy (Guest)
on 2009-02-12 09:56
(Received via mailing list)
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
  <body>
    <%= render :partial => 'shared/header' %>
    <div id="wrap">
      <div id="content">
        <%= yield %>
      </div>
    </div>
    <%= render :partial => 'shared/footer' %>
  </body>

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
MaD (Guest)
on 2009-02-12 10:04
(Received via mailing list)
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?
MaD (Guest)
on 2009-02-12 10:04
(Received via mailing list)
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?
zerogy (Guest)
on 2009-02-12 10:18
(Received via mailing list)
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:
<div id="footer-wrap">
  <div id="footer">
      <div class="bottom-links">
        <div class="bottom-nav">
          <ul>
            <li><a href="">About Us</a></li>
            <li><a href="">Privacy</a></li>
            <li><a href="">Contact Us</a></li>
            <li><a href="">Help</a></li>
          </ul>
        </div>
      </div>
  </div>
</div>

and each error has same informationm which is "wrong number of
arguments (3 for 1)"
MaD (Guest)
on 2009-02-12 10:43
(Received via mailing list)
> 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?
zerogy (Guest)
on 2009-02-12 10:54
(Received via mailing list)
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:
<div class="page-title">
<h1>Sign up as a new user</h1></div>

<% @user.password = @user.password_confirmation = nil %>
<div id="signup-area">
  <div class="left">
  <% if flash[:error] %>
    <div id="error">
      <%= flash[:error] %>
    </div>
  <% end %>
  <% form_for :user, :url => users_path, :html => {:class =>
'bigform'} do |f| -%>
    <div class="textfields">
      <div class="clearfix"><%= label_tag 'login' %>
      <%= f.text_field :login, :class=>"text" %><%= error_message_on
"user", "login" %></div>

      <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" %></div>
    </div>
    <div class="clearfix"><%= submit_tag 'Sign up' %></div>
  <% end -%>
  </div>
</div>

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?
MaD (Guest)
on 2009-02-12 11:28
(Received via mailing list)
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.
zerogy (Guest)
on 2009-02-12 11:34
(Received via mailing list)
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:
<div class="page-title">
<h1>Sign up as a new user</h1></div>

<% @user.password = @user.password_confirmation = nil %>
<div id="signup-area">
  <div class="left">
  <% if flash[:error] %>
    <div id="error">
      <%= flash[:error] %>
    </div>
  <% end %>
  <% form_for :user, :url => users_path, :html => {:class =>
'bigform'} do |f| -%>
    <div class="textfields">
      <div class="clearfix"><%= label_tag 'login' %>
      <%= f.text_field :login, :class=>"text" %><%= error_message_on
"user", "login" %></div>

      <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" %></div>
    </div>
    <div class="clearfix"><%= submit_tag 'Sign up' %></div>
  <% end -%>
  </div>
</div>

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?
zerogy (Guest)
on 2009-02-12 11:36
(Received via mailing list)
thank you very much and  i am going to debug to find out the source
problem
This topic is locked and can not be replied to.