我是rspec和模块的新手,自周五以来我一直对此有疑问。我想创建一个模块,可以调用/传递给Airport.rb文件,以在“晴天”和“暴风雨”之间随机分配天气。我在使用rspec时遇到问题,因此欢迎任何资源建议。
weather一直被rspec返回为未定义变量。
weather.rb(模块)
module Weather
def reading?
weather = ["Sunny", "Stormy"]
weather.sample
end
end
规格:
require './lib/weather'
class WeatherHolder; include Weather; end
describe Weather do
let(:holder) {WeatherHolder.new}
it "should read the weather" do
expect(weather).to eq(reading)
end
end
let(:holder) {WeatherHolder.new}
应该是let(:weather) {WeatherHolder.new}
,然后您需要弄清楚如何reading?
在weather变量上调用该函数。
尝试类似的东西
describe Weather do
let(:weather) {WeatherHolder.new}
it "should read the weather" do
expect(["Sunny", "Stormy"]).to include(weather.reading?)
end
end
这在我的计算机上有效。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句