私はレール上でルビーを学んでいますが、自分では解決できない問題があります。誰でも私を助けることができますか?私が実行したときにrspec-rails + capybara NoMethodError:未定義のメソッド `create '
:
Failure/Error: @user = create(:user) NoMethodError:
undefined method `create' for #<RSpec::ExampleGroups::User::PropertiesShouldNotNil:0xb807450>
# ./spec/models/user_spec.rb:6:in `block (3 levels) in <top (required)>'
Gemfile:
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '5.0.0.rc2'
# Use mysql as the database for Active Record
gem 'mysql2'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails', '~> 2.3.0'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'alipay', '~> 0.10.0' #支付宝接口
gem 'capistrano-rails', :group => :development
gem 'capistrano-passenger', :group => :development
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
# Access an IRB console on exception pages or by using <%= console %> in views
#gem 'web-console', '~> 2.0'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'rspec-rails'
gem "capybara"
end
group :development do
gem 'web-console', group: :development
end
スペック/ rails_helper.rb:
ENV["RAILS_ENV"] ||= 'test'
require 'spec_helper'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'capybara/rails'
require 'capybara/rspec'
ActiveRecord::Migration.maintain_test_schema!
RSpec.configure do |config|
config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.use_transactional_fixtures = true
config.infer_spec_type_from_file_location!
end
のexec RSpecの仕様/モデル/ user_spec.rbをバンドルし、私はこのエラーを得ました
app/models/user.rb
app/models/user.rb
has_many :recipients
end
仕様/モデル/ user_spec.rb:
require 'rails_helper'
RSpec.describe User, type: :model do
context "properties should not nil" do
before do
@user = create(:user)
end
subject{ @user }
it { should respond_to(:name) }
it { should respond_to(:passwd) }
end
end
Daniel Ruizさん、ありがとうございました。私の問題を解決するのに役立ちます。 – Lorbin