过程如下:
从控制台安装rspec gem:
gem install rspec
然后创建一个包含以下内容的文件夹(我们将其命名为root):
root/my_模型.rb
root/spec/my_model_spec.rb
#my_model.rb
class MyModel
def the_truth
true
end
end
#spec/my_model_spec.rb
require_relative '../my_model'
describe MyModel do
it "should be true" do
MyModel.new.the_truth.should be_true
end
end
然后在控制台中运行
rspec spec/my_model_spec.rb
瞧!