我正在浏览TestFirst教程,由于Rake(以及一般的rspec)存在一些问题,因此无法完成第一项挑战。
我正在尝试运行的测试:
require 'hello'
describe "the hello function" do
it "says hello" do
hello.should == "Hello!"
end
end
describe "the greet function" do
it "says hello to someone" do
greet("Alice").should == "Hello, Alice!"
end
it "says hello to someone else" do
greet("Bob").should == "Hello, Bob!"
end
end
我只能创建hello.rb文件(根据教程)并添加
def hello
end
为了记录,在我创建文件之前,我得到了长输出,说明了要求"你好"没有像预期的那样工作,并且创建了一个消失的文件。所以一切正常。
当我运行rake命令时,我的输出是(粗体部分是我的主要关注点):
wendy @ wendy-EL1352:〜/ the_odin_project / learn_ruby / 00_hello $ rake (在/ home / wendy / the_odin_project / learn_ruby) hello函数 你好(FAILED - 1)
故障:
1)hello函数说你好 失败/错误:hello.should =="你好!" 预期:"您好!" 得到:零(使用==) #。/ 00_hello / hello_spec.rb:120:在'
中的块(2级)弃用警告:
使用来自rspec-expectations'的
should
旧的:should
语法未明确启用>语法已弃用。使用新的:expect
语法或明确启用:should
>。来自/home/wendy/the_odin_project/learn_ruby/00_hello/hello_spec.rb:120:in>`块(2级)'。如果您需要更多这些弃用的回溯 确定在哪里进行必要的更改,您可以进行配置
config.raise_errors_for_deprecations!
,它会变成 将弃用警告转换为错误,为您提供完整的回溯。1弃用警告总数
以0.00334秒结束(文件加载0.14558秒) 1例,1次失败
失败的例子:
rspec ./00_hello/hello_spec.rb:119#hello函数说你好 耙子流产了! /home/wendy/.rvm/rubies/ruby-2.0.0-p481/bin/ruby -S rspec /home/wendy/the_odin_project/learn_ruby/00_hello/hello_spec.rb -I / home / wendy / the_odin_project / learn_ruby / 00_hello -I / home / wendy / the_odin_project / learn_ruby / 00_hello / solution -f documentation -r ./rspec_config failed /home/wendy/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/rake_task.rb:156:in
run_task' /home/wendy/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/rake_task.rb:124:in
块( 2级)初始化' /home/wendy/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/rake_task.rb:122:in`block in initialize' 任务:TOP =>默认=>规范 (通过使用--trace运行任务查看完整跟踪)
我并不十分关注弃用警告(我已经看得足以合理地确定这些与之相关)。虽然如果你认为这是我的原因,我会羞愧地低头。我确实需要弄清楚如何重写规范或更改配置设置,但我相信我自己可以做到这一点。我真正担心的是Rake可以访问测试并可以运行它们,但在显示错误消息之前中止。
如果我运行rspec hello_spec.rb,则输出在此处:
wendy @ wendy-EL1352:〜/ the_odin_project / learn_ruby / 00_hello $ rspec hello_spec.rb /home/wendy/.rvm/rubies/ruby-2.0.0-p481/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in
require': cannot load such file -- hello (LoadError) from /home/wendy/.rvm/rubies/ruby-2.0.0-p481/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in
要求&#39; 来自/home/wendy/the_odin_project/learn_ruby/00_hello/hello_spec.rb:116:in<top (required)>' from /home/wendy/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.0.2/lib/rspec/core/configuration.rb:1057:in
loading&#39; 来自/home/wendy/.rvm/gems/ruby-2.0.0-p481@raptionsutorial_rails_4_0/gems/rspec-core-3.0.2/lib/rspec/core/configuration.rb:1057:inblock in load_spec_files' from /home/wendy/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.0.2/lib/rspec/core/configuration.rb:1057:in
每个& #39; 来自/home/wendy/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.0.2/lib/rspec/core/configuration.rb:1057:inload_spec_files' from /home/wendy/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.0.2/lib/rspec/core/runner.rb:97:in
设置& #39; 来自/home/wendy/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.0.2/lib/rspec/core/runner.rb:85:inrun' from /home/wendy/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.0.2/lib/rspec/core/runner.rb:70:in
运行& #39; 来自/home/wendy/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.0.2/lib/rspec/core/runner.rb:38:ininvoke' from /home/wendy/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.0.2/exe/rspec:4:in
& #39; 来自/home/wendy/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/bin/rspec:23:inload' from /home/wendy/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/bin/rspec:23:in
&#39;
所以我有点想知道为什么运行rake链接所需的hello.rb文件没有问题但rspec命令没有。我只是想让这些测试正确运行(并且失败),这样我就可以继续执行任务了。
rakefile:
# This Rakefile has all the right settings to run the tests inside each lab
gem 'rspec', '~>2'
require 'rspec/core/rake_task'
task :default => :spec
desc "run tests for this lab"
RSpec::Core::RakeTask.new do |task|
lab = Rake.application.original_dir
task.pattern = "#{lab}/*_spec.rb"
task.rspec_opts = [ "-I#{lab}", "-I#{lab}/solution", '-f documentation', '-r ./rspec_config']
task.verbose = false
end
添加宝石&红宝石宝石&#39;什么都不做,只会增加输出的混乱。
我在之前的尝试中使用rspec --init初始化了rspec,无论是在00_hello目录还是在learn_ruby目录中。在这种情况下,我遇到了完全相同的错误消息。
过去几个月我一直在学习Ruby和Rails。有一两次,我几乎在这里问了一个问题,但是我已经在起草中途找到了答案。这次我没有那种运气。我真的很难过。请帮忙。
谢谢。
使用有关rspec的更多信息进行编辑 - 使用&#39; spec_helper&#39;
在00_hello文件夹中,rspec --init然后在hello_spec.rb中包含spec_helper(如上所示 - 我在require&#39; hello&#39;下面包括require&#39; spec_helper&#39;)使用rake命令运行时会产生以下错误:
wendy @ wendy-EL1352:〜/ the_odin_project / learn_ruby / 00_hello $ rake(in /家庭/温迪/ the_odin_project / learn_ruby) /home/wendy/.rvm/rubies/ruby-2.0.0-p481/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require&#39;:无法加载这样的文件 - spec_helper(LoadError)
在learn_ruby目录中,我得到与上面相同的输出,测试运行得足够好,但是后来我看到rake abort!在列出错误之前和之前的错误相同:
hello函数表示hello(FAILED - 1)
故障:
1)hello函数说你好 失败/错误:hello.should ==&#34;你好!&#34; NameError: 未定义的局部变量或方法
中hello' for #<RSpec::ExampleGroups::TheHelloFunction:0x00000002989278> # ./00_hello/hello_spec.rb:122:in
块(2级)在&#39;以0.00094秒结束(文件加载0.16985秒)1 例如,1次失败
失败的例子:
rspec ./00_hello/hello_spec.rb:121#hello函数说你好 耙子流产了! /home/wendy/.rvm/rubies/ruby-2.0.0-p481/bin/ruby -S rspec /home/wendy/the_odin_project/learn_ruby/00_hello/hello_spec.rb -I / home / wendy / the_odin_project / learn_ruby / 00_hello -I / home / wendy / the_odin_project / learn_ruby / 00_hello / solution -f documentation -r ./rspec_config failed
(测试失败的原因不同是因为我已经回过头来创建hello.rb文件而没有将类名插入到文件中 - 测试已经运行了一半,但是rake中止了!赢了& #39; t走开)
这家伙:
-I / home / wendy / the_odin_project / learn_ruby / 00_hello / solution -f documentation -r ./rspec_config failed
可以在Rakefile中找到:
RSpec::Core::RakeTask.new do |task|
lab = Rake.application.original_dir
task.pattern = "#{lab}/*_spec.rb"
**task.rspec_opts = [ "-I#{lab}", "-I#{lab}/solution", '-f documentation', '-r ./rspec_config']**
task.verbose = false
end
但是我对Rake的理解还不足以解析谷歌搜索结果中的问题,或者找到用于查找相关信息的搜索词。 :/