我正在尝试运行rspec测试,但我似乎无法让它在我的工作上运行 Mac吗?
player_spec.rb
文件包含:
require 'player'
describe Player do
end
所有其他相关文件都在同一个文件夹中
从命令行运行rspec player_spec.rb
会生成
以下错误:
/Users/lloyd_treleven/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in
`require': cannot load such file -- player (LoadError)
from
/Users/lloyd_treleven/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in
`require'
from /Users/lloyd_treleven/studio_game/player_spec.rb:1:in `<top
(required)>'
from
/Users/lloyd_treleven/.rvm/gems/ruby-1.9.3-p194/gems/rspec-core-2.10.1/lib/rspec/core/configuration.rb:746:in
`load'
from
/Users/lloyd_treleven/.rvm/gems/ruby-1.9.3-p194/gems/rspec-core-2.10.1/lib/rspec/core/configuration.rb:746:in
`block in load_spec_files'
from
/Users/lloyd_treleven/.rvm/gems/ruby-1.9.3-p194/gems/rspec-core-2.10.1/lib/rspec/core/configuration.rb:746:in
`map'
from
/Users/lloyd_treleven/.rvm/gems/ruby-1.9.3-p194/gems/rspec-core-2.10.1/lib/rspec/core/configuration.rb:746:in
`load_spec_files'
from
/Users/lloyd_treleven/.rvm/gems/ruby-1.9.3-p194/gems/rspec-core-2.10.1/lib/rspec/core/command_line.rb:22:in
`run'
from
/Users/lloyd_treleven/.rvm/gems/ruby-1.9.3-p194/gems/rspec-core-2.10.1/lib/rspec/core/runner.rb:69:in
`run'
from
/Users/lloyd_treleven/.rvm/gems/ruby-1.9.3-p194/gems/rspec-core-2.10.1/lib/rspec/core/runner.rb:10:in
`block in autorun'
我安装了以下rspec gem
rspec (2.10.0)
rspec-core (2.10.1)
rspec-expectations (2.10.0)
rspec-mocks (2.10.1)
目前我已安装rvm 1.13.4
目前我正在运行ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin10.8.0]
当我运行via textmate时,我收到以下错误消息:
NoMethodError: undefined method ‘describe’ for main:Object
我安装了RSpec textmate软件包:
mkdir -p ~/Library/Application\ Support/TextMate/Pristine\ Copy/Bundles
cd ~/Library/Application\ Support/TextMate/Pristine\ Copy/Bundles
git clone git://github.com/rspec/rspec-tmbundle.git RSpec.tmbundle
osascript -e 'tell app "TextMate" to reload bundles'
我做错了什么?
答案 0 :(得分:2)
找到了我需要在ruby文件顶部安装require_relative'player'的答案?一旦我这样做,我就可以从命令行运行rspec player_spec.rb并让测试执行。 TextMate仍然会抛出NoMethodError错误。我将检查textmate rspec bundle安装,看看这是否正确。
答案 1 :(得分:0)
我最近碰到了类似的东西,看起来你有两个问题:
player.rb
文件describe
阻止由于我不确定您的文件树是如何设置的,所以我们只是说它看起来像这样:
/studio_game
/lib
player.rb
/spec
player_spec.rb
spec_helper.rb
Gemfile
Gemfile.lock
.rspec
要解决您的LoadError
,您需要确保player_spec.rb
文件可以找到您的player.rb
文件。你可以这样做......
# like this:
require_relative '../lib/player'
# or like this:
require 'player'
现在开始解决您丢失的describe
方法错误。当我遇到此问题时,我发现我的.rspec
文件需要spec_helper
,如下所示:
--require spec_helper #<-- problematic for me
--color
--format doc
删除后,我的rspec套件正确运行。
--color
--format doc
答案 2 :(得分:-1)
您必须使用终端访问当前子文件夹:例如“lib”或“spec”
我得到了同样的错误,花了很长时间才发现:cd spec
然后rspec 00_hello_spec.rb
为我工作!