업데이트 2 : require {path_to_spec_helper}는 설정 미정의 문제를 해결하지만, 이제는 모든 정적 변수가 갑자기 정의되지 않고 모든 FactoryGirl 객체가 유효성 검사를 통과하지 못합니다 (검사에서 객체가 유효성 검사를 통과했음을 보여 주지만). 그리고 FactoryGirl을 save_with_validation (false)으로 변경하면 테스트에서 객체가 nil이되어 모든 것을 무력화시킵니다.Rspec과 Shoulda를 사용하면 왜 '설정'이 정의되지 않습니까?
UPDATE :
context "some context" do
ap self.respond_to?(:setup)
setup do
raise "stop"
을 그리고 respond_to 라인은 진정한 인쇄,하지만 아래의 method_missing 오류를 던져 진행 : 나는 내 코드에이를 던졌다. 그래서, 그냥 컨텍스트 내에서 정의되지 않은 것 같아요? 그런 식으로 사용되지 않았습니다.
원래의 게시물 : 어떤 이유
은 나에게 알 수없는,/should
/setup
context
내 테스트에서 정의되지 않은 것 같다. 모든 설정을 before(:each)
의 것으로 변경하면 should
또는 context
에 문제가있을 것입니다. 모든 rspec/shoulda matchers를 old-skool 스타일 describe
- before(:each)
- it{}
으로 변경하면 테스트가 실행되지만 실제로 실행되지는 않습니다. (콘솔의 진행 과정에서 아무런 테스트도 실행되지 않습니다 (점들 없음).
내 테스트 환경이 올바르게 설정되었는지 어떻게 확인할 수 있습니까? 여기
내 구성
보석 파일입니다
# can't be in test group because it's required in the rake file
gem "single_test"# because running all the tests all the time takes too long
group :test do
# helper gems
gem "rspec-rails", "1.3.4"
gem "rspec", "1.3.2"
gem "shoulda"
gem "database_cleaner"
gem "crack" #for XML/JSON conversion
gem "mocha" #required for .requires and .stubs
gem "factory_girl", :require => false
# view and functional
gem "capybara", "1.1.1"
gem "cucumber", "1.1.0"
gem "cucumber-rails", "0.3.2"
gem "culerity"
gem "launchy"
gem "hpricot"
gem "gherkin"
gem "rack"
gem "webrat"
# tools
gem "json"
gem "curb"
end
필수 시험 hepler에서 일 :
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
require "bundler/setup"
Bundler.require(:test)
require 'test_help'
require 'spec'
require 'spec/expectations'
require 'factory_girl'
바이너리 정보 :
루비 1.8.7
RVM 1.7 .2
개 보석 1.8.21
번들 1.1.4
레이크 0.9.2.2
레일
2.3.14 그리고 내 오류 :
`method_missing': undefined method `setup' for Spec::Example::ExampleGroup::Subclass_1:Class (NoMethodError)
스택 추적 :
from test/unit/my_test.rb:257
from /Users/me/.rvm/gems/ruby-1.8.7-p352/gems/rspec-1.3.2/lib/spec/example/example_group_methods.rb:188:in `module_eval'
from /Users/me/.rvm/gems/ruby-1.8.7-p352/gems/rspec-1.3.2/lib/spec/example/example_group_methods.rb:188:in `subclass'
from /Users/me/.rvm/gems/ruby-1.8.7-p352/gems/rspec-1.3.2/lib/spec/example/example_group_methods.rb:55:in `describe'
from /Users/me/.rvm/gems/ruby-1.8.7-p352/gems/rspec-1.3.2/lib/spec/example/example_group_factory.rb:31:in `create_example_group'
스택의 마지막 코드 비트 라인 257 주위에 코드 :
context "some context" do
setup do
...
당신은'당신의 명세 파일의 상단에 'spec_helper''를 필요가 있습니까 :
당신은
rails_helper.rb
여기spec_helper.rb
의 자세한 구성을 확인할 수 있습니까? – Flexoid스펙 파일이 없습니까? 또는 스펙 도우미? 이 모든 테스트는 teh/test 디렉토리에있다. – NullVoxPopuli