运行Rspec时“没有这样的文件加载”错误

时间:2009-01-07 00:50:01

标签: ruby-on-rails ruby testing rspec

Mac OS 10.4
rspec (1.1.11, 1.1.4, 1.1.3, 0.5.15)
rspec-rails (1.1.11)
rspec_generator (0.5.15)
rails 2.2.2
ruby 1.8.6 (2007-03-13 patchlevel 0) [universal-darwin8.0]

创建了一个新项目......

$ rails myproject

将rspec安装到项目中......

$ script/generate rspec

生成资源......

$ script/generate rspec_scaffold myresource name:string description:text

试图运行规格......

$ rake spec

出现此错误:

/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- ./spec/models/../../vendor/generators/rspec/lib/rspec_on_rails (MissingSourceFile)
        from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
        from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:155:in `require'
        from ./spec/models/../spec_helper.rb:3
        from ./spec/models/entry_spec.rb:1:in `require'
        from ./spec/models/entry_spec.rb:1
        from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/example_group_runner.rb:14:in `load'
        from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/example_group_runner.rb:14:in `load_files'
        from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/example_group_runner.rb:13:in `each'
        from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/example_group_runner.rb:13:in `load_files'
        from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/options.rb:98:in `run_examples'
        from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/command_line.rb:10:in `run'
        from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/bin/spec:4
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- /Users/ethan/project/project/spec/../vendor/generators/rspec/lib/rspec_on_rails (MissingSourceFile)
        from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
        from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:155:in `require'
        from /Users/ethan/project/project/spec/spec_helper.rb:3
            from ./spec/controllers/entries_controller_spec.rb:1:in `require'
        from ./spec/controllers/entries_controller_spec.rb:1
        from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/example_group_runner.rb:14:in `load'
        from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/example_group_runner.rb:14:in `load_files'
        from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/example_group_runner.rb:13:in `each'
        from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/example_group_runner.rb:13:in `load_files'
        from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/options.rb:98:in `run_examples'
        from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/lib/spec/runner/command_line.rb:10:in `run'
        from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.11/bin/spec:4

的确,没有这样的档案......

vendor / generators,ls:

rspec_controller        rspec_model

2 个答案:

答案 0 :(得分:27)

对于rails3

获取列表

$ rails generate 

生成spec_helper.rb

$ rails g rspec:install

答案 1 :(得分:9)

这似乎对我有用。 我已经安装了 rspec-rails ,运行了rspec生成器,当我提供

$ script/generate

我得到了生成器列表:

  

已安装的发电机     Rubygems:rspec,rspec_controller,rspec_model,rspec_scaffold     Builtin:controller,integration_test,mailer,migration,model,observer,performance_test,plugin,resource,scaffold,session_migration

rspec_scaffold 生成脚手架后,规格通过。 您的rails项目中的供应商/生成器是项目吗?我认为你应该删除它们并使用gems中的生成器。