我有一个'未定义的方法让'尝试运行minitest规范时出错。
以下是规范:
require 'test_helper'
extend Minitest::Spec::DSL
class AccountTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
let(:entity) { Entity.create }
let(:user) { User.create(plan: 0, entity: entity) }
test 'valid account' do
account = Account.new(user_id: user, name: 'Нал', type: :cash, currency: 'RUB', category: :regular)
assert account.valid?
end
end
这是test_helper文件:
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
require 'minitest/autorun'
require 'shoulda/context'
require 'shoulda/matchers'
require 'minitest/reporters'
Minitest::Reporters.use!
include FactoryGirl::Syntax::Methods
class ActiveSupport::TestCase
fixtures :all
end
这是Gemfile的一部分:
group :development, :test do
gem 'binding_of_caller'
gem "minitest-rails"
gem 'shoulda'
gem 'minitest-reporters'
gem 'pry'
gem 'minitest-rails-capybara'
gem 'capybara'
gem 'factory_girl'
end
我有什么问题? :)
答案 0 :(得分:1)
您需要向测试助手添加以下要求:
require "minitest/rails"
如果添加要求,则不需要在测试中使用extend Minitest::Spec::DSL
。
答案 1 :(得分:0)
let
仅在describe
内定义。
尝试将其放入describe
describe "let" do
let(:entity) { Entity.create }
let(:user) { User.create(plan: 0, entity: entity) }