1
내 RSpec에 테스트를하고 있는데 그것은 다음과 같은 출력 것 :Rspec에서 expect 메소드가 누락 된 것 같습니다. 올바른가요?
Failure/Error: expect {
NoMethodError:
undefined method `[]' for nil:NilClass
# ./spec/controllers/users_controller_spec.rb:44:in `block (4 levels) in <top (required)>'
오류가 참조하는 줄 것은 "{기대"라고 선이다. 나는 지구상에서 무엇이 잘못되고 있는지 잘 모르겠습니다. 잘못된 여기에 무슨 일이 일어나고 있는지에
require 'spec_helper'
describe UsersController do
def valid_attributes
{
:username => "tester",
:email => "[email protected]",
:password => "testingpass"
}
end
def valid_session
{}
end
describe "POST create" do
describe "with valid params" do
it "creates a new User" do
expect {
post :create, {:user => valid_attributes , :format => :json}, valid_session
}.to change(User, :count).by(1)
end
end
end
end
어떤 아이디어 :
여기에 전체 스펙은?
주석 기
업데이트는 spec_helper.rb 파일을 요청했다. 아래에 게시하고 있습니다 ... rspec에 의해 생성 된 기본 설정입니다. 오류 메시지가 nil
에 []
을 실종 말한다 -
# 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 'rspec/autorun'
# 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}
RSpec.configure do |config|
# ## Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false
# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = "random"
end
이것은 잘 작동합니다. 'user.rb'와'spec_helper.rb'의 관련 부분을 볼 수 있습니까? – jordanpg
방금 프로젝트를 실행 했으므로 user.rb와 관련된 문제가 발생하지 않으며 사용자를 완벽하게 만들고 삭제합니다. 자동 생성 된 버전 인 spec_helper.rb로 업데이트를 게시하고 있습니다. –
'user.rb' 또는'users_controller.rb'를 변경 했습니까? 그것은 다음으로 볼 곳입니다. – jordanpg