运行测试时出现此错误
spec/helpers/bikes_helper_spec.rb:3:in `<top (required)>':
uninitialized constant BikesHelper (NameError)
bikes_helper
require "spec_helper"
describe BikesHelper do
describe "#km_until_next_service" do
it 'returns a human readable number' do
expect(km_until_next_service(1000)).to eq '1000 kilometers'
end
end
end
应用/助手/ bikes_helper.rb
module BikesHelper
include ActionView::Helpers::NumberHelper
def km_until_next_service(km_untill_next)
if km_untill_next == 0
return "NOW"
elsif (km_untill_next < 0)
return "Overdue by #{number_to_human(km_untill_next, unit: :distance)}"
elsif (km_untill_next > 0)
return "In #{number_to_human(km_untill_next, unit: :distance)}"
end
end
end
知道为什么它不承认BikesHelper?
答案 0 :(得分:3)
尝试
require 'rails_helper'
而不是
require 'spec_helper'