Sono nuovo di rspec e dei moduli e ho avutoproblemi con questo dal fri. Voglio creare un modulo che posso chiamare / passare al mio file Airport.rb per far coincidere il tempo tra "soleggiato" e "tempestoso". Ho problemi con il lavoro con rspec quindi ogni suggerimento sulle risorse è ben accetto.
il tempo continua a essere restituito da rspec come variabile indefinita.
weather.rb (modulo)
module Weather
def reading?
weather = ["Sunny", "Stormy"]
weather.sample
end
end
Spec:
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
risposte:
1 per risposta № 1let(:holder) {WeatherHolder.new}
dovrebbe essere let(:weather) {WeatherHolder.new}
e quindi è necessario capire come chiamare il reading?
funzione sulla variabile del tempo.
Prova qualcosa come
describe Weather do
let(:weather) {WeatherHolder.new}
it "should read the weather" do
expect(["Sunny", "Stormy"]).to include(weather.reading?)
end
end
Funziona sul mio computer.
1 per risposta № 2
Non hai definito weather
nelle tue specifiche, né reading
per questo motivo. Presumibilmente tu vuoi un expect
espressione che coinvolge holder.reading?
.