更新 2:require {path_to_spec_helper} 解决了设置未定义的问题,但现在所有的静态变量都突然未定义,并且所有 FactoryGirl 制造的对象都没有通过验证(即使检查表明该对象应该通过验证)。并且将 FactoryGirl 更改为 save_with_validation(false) 只会使我的测试中的对象为零,从而破坏了一切。
更新:我把它扔到我的代码中:
context "some context" do
ap self.respond_to?(:setup)
setup do
raise "stop"
并且respond_to 行打印为true,但随后继续抛出下面的method_missing 错误。所以,我猜它只是在上下文中未定义?以前不是这样的。
原帖:
出于某种原因,我不知道,似乎context
/ should
/setup
在我的测试中未定义。我会将所有设置更改为's ,然后orbefore(:each)
就会出现问题。当我将所有 rspec / shoulda 匹配器更改为老式风格的- -时,我的测试将运行,但实际上不会被执行。(控制台中的进度显示没有正在运行的测试(无点))。should
context
describe
before(:each)
it{}
那么,我想,如何验证我的测试环境是否设置正确?
这是我的配置
gem文件:
# 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'
二进制信息:
ruby 1.8.7
rvm 1.7.2
gem 1.8.21
bundle 1.1.4
rake 0.9.2.2
rails 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
...