尝试在 Ruby 和 Rails 项目中使用 RSpec。从命令行可以正常工作,但 TextMate 中的 Cmd-R 会导致NameError: uninitialized constant RSpec
spec/coffee_spec.rb:
class Coffee
def ingredients
@ingredients ||= []
end
def add(ingredient)
ingredients << ingredient
end
def price
1.00
end
end
RSpec.describe 'A cup of coffee' do
let(:coffee) { Coffee.new }
it 'costs $1' do
expect(coffee.price).to eq(1.00)
end
context 'with milk' do
before { coffee.add :milk }
it 'costs $1.25' do
expect(coffee.price).to eq(1.25)
end
end
end
我首先尝试coffee_spec.rb在 Ruby 中从 Marston-Dees 运行并遇到同样的问题,但也在 Rails 项目中尝试了相同的结果。