Я полностью озадачен этой ошибкой.Был бы очень признателен за помощь:).
Чтобы воспроизвести ошибку, вы можете извлечь программу из https://github.com/WaleyChen/twitter_clone. Затем запустите 'bundle exec rspec spec /'.
У меня естьТест rspec для моего контроллера определен как:
require 'spec_helper'
describe FrontpageController do
render_views # render the views inside the controller tests, so not just test the actions
describe "GET 'frontpage'" do
it "should be successful" do
get 'frontpage'
response.should be_success
end
it "should have the right title" do
get 'frontpage'
response.should have_selector("title", :content => "Twitter")
end
end
end
Когда я запускаю свои тесты rspec, я получаю следующую ошибку:
Failures:
1) FrontpageController GET 'frontpage' should be successful
Failure/Error: get 'frontpage'
ActionView::Template::Error:
undefined method `full_name' for #<User:0x007fbfce43dce0>
# ./app/views/frontpage/frontpage.html.erb:22:in `block in _app_views_frontpage_frontpage_html_erb___4518234645475110659_70230885952360'
# ./app/views/frontpage/frontpage.html.erb:21:in `_app_views_frontpage_frontpage_html_erb___4518234645475110659_70230885952360'
# ./spec/controllers/frontpage_controller_spec.rb:8:in `block (3 levels) in <top (required)>'
2) FrontpageController GET 'frontpage' should have the right title
Failure/Error: get 'frontpage'
ActionView::Template::Error:
undefined method `full_name' for #<User:0x007fbfcc99a410>
# ./app/views/frontpage/frontpage.html.erb:22:in `block in _app_views_frontpage_frontpage_html_erb___4518234645475110659_70230885952360'
# ./app/views/frontpage/frontpage.html.erb:21:in `_app_views_frontpage_frontpage_html_erb___4518234645475110659_70230885952360'
# ./spec/controllers/frontpage_controller_spec.rb:13:in `block (3 levels) in <top (required)>'
Вот контроллер:
class FrontpageController < ApplicationController
def frontpage
@user = User.new
@sign_up = User.new
end
def sign_up
if @post.save
format.html { redirect_to @post, notice: 'Post was successfully created.' }
end
end
end
Вот представление, которое вызывает ошибку:
<%= form_for @user, :url =>"sign_up" do |form| %>
<%= form.text_field :full_name, :placeholder => "Full name" %>
</br>
<%= form.text_field :email, :placeholder => "Email" %>
</br>
<%= form.text_field :pw, :placeholder => "Password" %>
</br>
<%= form.text_field :username, :placeholder => "Username" %>
</br>
<%= form.submit "Sign up" %>
<% end %>
Вот user.rb:
class User < ActiveRecord::Base
end
Вот схема.rb:
ActiveRecord::Schema.define(:version => 20111106084309) do
create_table "users", :force => true do |t|
t.string "full_name"
t.string "email"
t.string "username"
t.string "pw"
t.datetime "created_at"
t.datetime "updated_at"
end
end