我目前在执行以下 rspec 命令时得到以下输出:
MacBook-Pro:01_temperature fr$ gem install rspec
Successfully installed rspec-2.14.1
Parsing documentation for rspec-2.14.1
Done installing documentation for rspec after 0 seconds
1 gem installed
MacBook-Pro:01_temperature fr$ rspec --init
create spec/spec_helper.rb
create .rspec
MacBook-Pro:01_temperature fr$ rspec temperature_spec.rb
/Users/fr/Downloads/learn_ruby-master/01_temperature/temperature_spec.rb:18:in `require_relative': cannot load such file -- /Users/fr/Downloads/learn_ruby-master/01_temperature/temperature (LoadError)
from /Users/fr/Downloads/learn_ruby-master/01_temperature/temperature_spec.rb:18:in `<top (required)>'
from /Users/fr/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896:in `load'
from /Users/fr/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896:in `block in load_spec_files'
from /Users/fr/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896:in `each'
from /Users/fr/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896:in `load_spec_files'
from /Users/fr/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.7/lib/rspec/core/command_line.rb:22:in `run'
from /Users/fr/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.7/lib/rspec/core/runner.rb:80:in `run'
from /Users/fr/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.7/lib/rspec/core/runner.rb:17:in `block in autorun'
请参阅文件 temperature_spec.rb 的源代码
require "temperature"
describe "temperature conversion functions" do
describe "#ftoc" do
it "converts freezing temperature" do
ftoc(32).should == 0
end
it "converts boiling temperature" do
ftoc(212).should == 100
end
it "converts body temperature" do
ftoc(98.6).should == 37
end
it "converts arbitrary temperature" do
ftoc(68).should == 20
end
end
describe "#ctof" do
it "converts freezing temperature" do
ctof(0).should == 32
end
it "converts boiling temperature" do
ctof(100).should == 212
end
it "converts arbitrary temperature" do
ctof(20).should == 68
end
it "converts body temperature" do
ctof(37).should be_within(0.1).of(98.6)
# Why do we need to use be_within?
# See http://www.ruby-forum.com/topic/169330
# and http://en.wikipedia.org/wiki/IEEE_754-2008
# and http://en.wikipedia.org/wiki/Double_precision_floating-point_format
# Also, try "puts 0.5 - 0.4 - 0.1" -- pretty crazy, right?
end
end
end