Ruby on rails 使用Rspec和Shoulda,为什么“设置”未定义?
更新2:require{path_to_spec_helper}解决了安装程序未定义的问题,但现在所有静态变量都突然未定义,并且所有FactoryGirl生成的对象都未通过验证,即使检查表明该对象应通过验证。将FactoryGirl更改为使用_validationfalse保存_只会使对象在我的测试中为零,破坏一切 更新: 我在代码中加入了以下内容:Ruby on rails 使用Rspec和Shoulda,为什么“设置”未定义?,ruby-on-rails,unit-testing,rspec,shoulda,Ruby On Rails,Unit Testing,Rspec,Shoulda,更新2:require{path_to_spec_helper}解决了安装程序未定义的问题,但现在所有静态变量都突然未定义,并且所有FactoryGirl生成的对象都未通过验证,即使检查表明该对象应通过验证。将FactoryGirl更改为使用_validationfalse保存_只会使对象在我的测试中为零,破坏一切 更新: 我在代码中加入了以下内容: context "some context" do ap self.respond_to?(:setup) setup do
context "some context" do
ap self.respond_to?(:setup)
setup do
raise "stop"
而response_to line printed true,但随后继续抛出下面的方法_missing error。所以,我猜它只是在上下文中没有定义?过去不是这样的
原职:
出于某种原因,我不知道,在我的测试中似乎没有定义context/should/setup。我会把所有的设置都改为before:每个都是,然后就会出现should或context的问题。当我将所有rspec/shoulda匹配器更改为旧的skool样式descripe-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
创业板1.8.21
束1.1.4
rake 0.9.2.2
轨道2.3.14
我的错误是:
堆栈跟踪:
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/spec\u helper.rb和spec/rails\u helper.rb文件。可以使用以下命令执行此操作: rails生成rspec:install 创建文件后,请确保rails\u helper.rb需要spec\u helper.rb,否则它将不起作用,需要在spec文件上添加rails\u helper
您可以在此处查看rails\u helper.rb和spec\u helper.rb的更详细配置:您的spec文件顶部是否需要“spec\u helper”?我没有spec文件?还是规范助手?所有这些测试都在teh/test目录中
context "some context" do
setup do
...