0
# encoding: utf-8
class UsersController < ApplicationController
def index
@search = User.search(params[:search])
@users = @search.paginate :per_page => 20, :page => params[:page]
end
end
<h2>User search</h2>
<%= form_for @search, :url => users_path, :html => { :method => :get } do |f| %>
#some form elements
<% end %>
<% @users.each do |user| %>
# show user info
<% end %>
現在如何使用rspec 2測試視圖?如何使用rspec測試搜索視圖頁面?
# encoding: utf-8
require 'spec_helper'
describe "users/index.html.erb" do
before(:each) do
####@user = stub_model(User)
######User.stub!(:search).and_return(@post)
How to mock? If not mock(or stubed), it will got a nil error when rspec test.
end
it "renders a list of users" do
render
rendered.should contain("User search")
end
end
非常感謝您的回答。 ruby-1.9.2-p0> User.search.class MetaSearch :: Searches :: User
qichunren
2011-02-17 09:30:16