Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 4 失败/错误:登录用户未定义的方法“登录';_Ruby On Rails 4_Railstutorial.org - Fatal编程技术网

Ruby on rails 4 失败/错误:登录用户未定义的方法“登录';

Ruby on rails 4 失败/错误:登录用户未定义的方法“登录';,ruby-on-rails-4,railstutorial.org,Ruby On Rails 4,Railstutorial.org,我被困在Rails教程的第9章中,更具体地说是在第9.1节的末尾。我的问题与中的问题相似,但那里的解决方案对我不起作用 以下是我的用户\u页面\u spec.rb: require 'spec_helper' describe "User pages" do subject { page } describe "signup page" do before { visit signup_path } it { should have_content('Sign up') } it { sho

我被困在Rails教程的第9章中,更具体地说是在第9.1节的末尾。我的问题与中的问题相似,但那里的解决方案对我不起作用

以下是我的用户\u页面\u spec.rb:

require 'spec_helper'
describe "User pages" do
subject { page }

describe "signup page" do
before { visit signup_path }

it { should have_content('Sign up') }
it { should have_title(full_title('Sign up')) }
end

describe "profile page" do
let (:user) {FactoryGirl.create(:user)}
before { visit user_path(user) }

it { should have_content(user.name) }
it { should have_title(user.name) }
end

describe "signup" do

before { visit signup_path }

let(:submit) { "Create my account" }

describe "with invalid information" do
  it "should not create a user" do
    expect { click_button submit }.not_to change(User, :count)
  end
end

describe "with valid information" do
  before do
    fill_in "Name",         with: "Example User"
    fill_in "Email",        with: "user@example.com"
    fill_in "Password",     with: "foobar"
    fill_in "Confirmation", with: "foobar"
  end

  it "should create a user" do
    expect { click_button submit }.to change(User, :count).by(1)
  end
end
end

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

describe "with invalid information" do
  before { click_button "Save changes"}

  it { should have_content('error') }
end

describe "with valid information" do
  let(:new_name) { "New Name"}
  let(:new_email) {new@example.com}
  before do
    fill_in "Name", with: new_name
    fill_in "Email", with: new_email
    fill_in "Password", with: user.password
    fill_in "Confirm Password", with: user.password
    click_button "Save changes"
  end

  it {should have_title(new_name)}
  it {should have_selector('div.alert.alert-success')}
  it {should have_link('Sign out', href: signout_path)}
  specify {expect(user.reload.name).to eq new_name}
  specify {expect(user.reload.email).to eq new_email}
end
end
end
以下是错误消息:

bundle exec rspec spec/
.............................................FFFFFFFFF

Failures:

 1) User pages edit page 
 Failure/Error: sign_in user
 NoMethodError:
   undefined method `sign_in' for #<RSpec::Core::ExampleGroup::Nested_4::Nested_4::Nested_1:0x007faa37859d80>
 # ./spec/requests/user_pages_spec.rb:49:in `block (3 levels) in <top (required)>'

有什么建议吗?

当我试图安装rcov时,我确实运行了bundle安装(Rubymine抱怨它的缺乏)。安装失败,因为rcov不适用于我的rails版本。那很好

真正奇怪的是,之后我重新运行了测试,一切正常。没有错误消息的痕迹。我是一个rails noob,但这有点丰富——一个失败的捆绑包安装不会改变任何东西。我观察到的错误消息没有任何原因,现在它无缘无故地消失了


==编辑:我意识到问题在于rails似乎没有在测试之间清空缓存(在我看来,这是一个可怕的bug)。默认情况下,它无法重新读取文件,因此可能会忽略已发生的更改。我在这里提供了更多详细信息:

我怀疑您在spec helper中的任何位置都没有特别要求或包含
spec/support/utilities.rb
?事实上,我是这样做的。spec助手中有一行代码:
Dir[Rails.root.join(“spec/support/***.rb”)]。每个{f | require f}
,这样就可以了。我总是使用模块来管理这样的事情:感谢您的建议-我决定忠实地遵循教程,因为这是我第一次使用rails,所以我认为它可以最大限度地减少这种情况。我真的不知道为什么方法中的
符号不被识别。
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]
user.update_attribute(:remember_token, User.digest(remember_token))
else
visit signin_path
fill_in "Email", with: user.email
fill_in "Password", with: user.password
click_button "Sign in"
end
end