Ruby on rails FactoryGirl+Rspec+Rails3失败
我有一个来自我大学的项目,我试图在做任何更改之前理解代码 代码中有测试,这使得这更容易。但是我在运行这些测试时遇到了问题。编写代码的人说它工作得很完美,所以我认为它与gems或类似的东西不兼容。该项目有一年多没有更新,这就是为什么宝石可能有点旧rs。但由于我没有改变任何宝石,这应该工作。让我们转到问题: 这是我的测试:Ruby on rails FactoryGirl+Rspec+Rails3失败,ruby-on-rails,ruby,rspec,factory-bot,Ruby On Rails,Ruby,Rspec,Factory Bot,我有一个来自我大学的项目,我试图在做任何更改之前理解代码 代码中有测试,这使得这更容易。但是我在运行这些测试时遇到了问题。编写代码的人说它工作得很完美,所以我认为它与gems或类似的东西不兼容。该项目有一年多没有更新,这就是为什么宝石可能有点旧rs。但由于我没有改变任何宝石,这应该工作。让我们转到问题: 这是我的测试: it 'edit user information' do user = FactoryGirl.create :user login(user.email, '1234
it 'edit user information' do
user = FactoryGirl.create :user
login(user.email, '123456')
click_link user.email
fill_in 'E-mail', :with => 'another_email@email.com'
click_button 'Save'
page.should have_content 'Update successfull.'
end
这是我的登录函数,位于spec_helper
def login(email, password)
visit '/admin'
fill_in('user_email', :with => email)
fill_in('user_password', :with => password)
click_button "Entrar"
end
这就是错误:
1) login and register edit user information
Failure/Error: login(user.email, '123456')
ArgumentError:
wrong number of arguments (1 for 0)
# ./spec/acceptance/login_spec.rb:18:in `block (2 levels) in <top (required)>'
有人能帮我解决这个问题吗
编辑:
工厂用户:
# -*- encoding : utf-8 -*-
FactoryGirl.define do
factory :user do
sequence(:email) { |n| "user#{n}@email.com" }
password "123456"
password_confirmation "123456"
admin true
end
end
spec_helper.rb:
# -*- encoding : utf-8 -*-
require 'rubygems'
require 'spork'
Spork.prefork do
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'capybara/rspec'
require 'valid_attribute'
require 'cancan/matchers'
require 'paperclip/matchers'
IMAGE = File.expand_path("../data/image.jpg", __FILE__)
TEXT = File.expand_path("../data/text.txt", __FILE__)
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
Capybara.javascript_driver = :webkit
RSpec.configure do |config|
config.mock_with :rspec
config.use_transactional_fixtures = false
config.include Paperclip::Shoulda::Matchers
config.before :each do
if example.metadata[:js]
Capybara.server_port = 33333
Capybara.current_driver = :webkit
end
if Capybara.current_driver == :rack_test
DatabaseCleaner.strategy = :transaction
else
DatabaseCleaner.strategy = :truncation
end
DatabaseCleaner.start
end
config.after do
DatabaseCleaner.clean
Capybara.use_default_driver if example.metadata[:js]
end
end
def login(email, password)
visit '/admin'
fill_in('user_email', :with => email)
fill_in('user_password', :with => password)
click_button 'Entrar'
end
end
Spork.each_run do
require File.expand_path("../../config/routes", __FILE__)
load "#{Rails.root}/config/routes.rb"
Dir["#{Rails.root}/app/**/*.rb"].each { |f| load f }
end
登录\u spec.rb:
# -*- encoding : utf-8 -*-
require 'spec_helper'
feature 'login and register' do
background do
FactoryGirl.create :configuration
end
it 'should not be possible guest user register an administrator' do
visit '/admin'
page.should_not have_content 'Registrar'
lambda { visit '/users/sign_up' }.should raise_error ActionController::RoutingError
end
it 'edit user information' do
user = FactoryGirl.create :user
login(user.email, '123456')
click_link user.email
fill_in 'E-mail', :with => 'outro_email@email.com'
click_button 'Salvar'
page.should have_content 'Usuário atualizado(a) com sucesso.'
end
end
你的用户工厂里有什么?您是否尝试使用另一个方法名称,因为“login”是由Deviate定义的?嗨@Mariekou,我尝试过这样做。现在我改为我的_登录,我得到了相同的错误。我刚刚编辑了这篇文章并在那里添加了我的工厂,你能检查一下吗?非常奇怪的错误。尝试删除登录方法并检查错误消息是否已更改。@AlexanderKarmes如果这样做,我会发现错误未定义方法登录:确定。然后显示完整的spec_helper.rb并登录spec.rb
# -*- encoding : utf-8 -*-
require 'spec_helper'
feature 'login and register' do
background do
FactoryGirl.create :configuration
end
it 'should not be possible guest user register an administrator' do
visit '/admin'
page.should_not have_content 'Registrar'
lambda { visit '/users/sign_up' }.should raise_error ActionController::RoutingError
end
it 'edit user information' do
user = FactoryGirl.create :user
login(user.email, '123456')
click_link user.email
fill_in 'E-mail', :with => 'outro_email@email.com'
click_button 'Salvar'
page.should have_content 'Usuário atualizado(a) com sucesso.'
end
end