为RSpec rails 5创建未定义的方法
可能是一个复制品,但它对我不起作用。 请让我知道我错过了什么 配置详细信息:为RSpec rails 5创建未定义的方法,rspec,ruby-on-rails-5,factory-bot,rspec-rails,Rspec,Ruby On Rails 5,Factory Bot,Rspec Rails,可能是一个复制品,但它对我不起作用。 请让我知道我错过了什么 配置详细信息: #Gemfile gem 'factory_bot_rails' # 4.8.2 #spec/rails_helper.rb RSpec.configure do |config| config.include FactoryBot::Syntax::Methods #other config end spec/factories/otps.rb FactoryBot.define do factory
#Gemfile
gem 'factory_bot_rails' # 4.8.2
#spec/rails_helper.rb
RSpec.configure do |config|
config.include FactoryBot::Syntax::Methods
#other config
end
spec/factories/otps.rb
FactoryBot.define do
factory :otp do
phone { Faker::Number.number(10) }
expiry { Time.now + Otp::Constants::EXPIRY_DURATION }
password { Faker::Number.number(4) }
end
end
require 'spec_helper'
RSpec.describe "Authentication", :type => :request do
describe "when invalid OTP is passed" do
it "should return bad request" do
otp = create(:otp) # ===> Throws error
end
end
end
spec/requests/authentication\u controller\u spec.rb
FactoryBot.define do
factory :otp do
phone { Faker::Number.number(10) }
expiry { Time.now + Otp::Constants::EXPIRY_DURATION }
password { Faker::Number.number(4) }
end
end
require 'spec_helper'
RSpec.describe "Authentication", :type => :request do
describe "when invalid OTP is passed" do
it "should return bad request" do
otp = create(:otp) # ===> Throws error
end
end
end
更改等级库以包含正确的辅助对象:
require 'rails_helper'
RSpec.describe "Authentication", :type => :request do
describe "when invalid OTP is passed" do
it "should return bad request" do
otp = create(:otp)
end
end
end
如果使用.rspec
文件,也可以跳过该行,该文件将包括以下内容:
--color
--format progress
--order random
--require rails_helper