【发布时间】:2015-01-26 17:00:46
【问题描述】:
在 Michael Hartl 的 Ruby on Rails 教程的第 9 章中,我遇到了 RSpec 测试的问题,因为他们看不到文件 utility.rb 中定义的我的 sign_in 方法。我被卡住了,我检查了一切,似乎是正确的。我看到了类似的帖子,其中包含 ApplicationHelper 帮助某人的行,但我已经有了它,而且我对包含在同一文件中的方法“full_title”没有任何问题。
utilities.rb:
def full_title(page_title)
base_title = "Ruby on Rails Tutorial Sample App"
if page_title.empty?
base_title
else
"#{base_title} | #{page_title}"
end
end
def sign_in(user, options={})
if options[:no_capybara]
#Sign in when not using Capybara
remember_token = User.new_remember_token
cookies[:remember_token] = remember_token
user.update_attribute(:remember_token, User.encrypt(remember_token))
else
visit signin_path
fill_in "Email", with: user.email
fill_in "Password", with: user.password
click_button "Sign in"
end
end
以及失败的文件 user_pages_spec.rb:
require 'rails_helper'
include ApplicationHelper
...
...
...
describe "edit" do
let(:user) { FactoryGirl.create(:user) }
before do
sign_in user
visit edit_user_path(user)
end
describe "page" do
it { should have_content("Update your profile") }
it { should have_title("Edit user") }
it { should have_link('change', href: 'http://gravatar.com/emails') }
end
...
end
【问题讨论】:
标签: ruby-on-rails ruby rspec railstutorial.org