を実行しません取得します。RSpecのは、ストリップテストは、私は現在の方法をスペックしようとしています
class CLIinterface
def units_inputs
puts "\n\n________________________________________________________________________________________________________________________\nEnter the desired unit class of measurement desired for current temperature:\n\t- Typing 'standard', 'default' or 'any word != imperial or metric' induces the selection of Standard (Kelvin)\n\t- Typing 'imperial' induces the selection of Imperial (Fahrenheit)\n\t- Typing 'metric' induces the selection of Metric (Celsius)\n________________________________________________________________________________________________________________________\n"
# \n
# \n________________________________________________________________________________________________________________________
# \nEnter the desired unit class of measurement desired for current temperature:
# \n\t- Typing 'standard', 'default' or 'any word != imperial or metric' induces the selection of Standard (Kelvin)
# \n\t- Typing 'imperial' induces the selection of Imperial (Fahrenheit)
# \n\t- Typing 'metric' induces the selection of Metric (Celsius)
# \n________________________________________________________________________________________________________________________
# \n
@units_input = gets.strip.to_s.downcase
end
end
は、どのように私はテスト行くのです@units_input
変数インスタンスはgets.strip.to_s.downcase
を通じてユーザー入力に設定されていること?私はそれに悩まされている。私は答えを見つけることができません。
describe 'units_inputs' do
let(:units_input) { double("metric") }
let(:unit) { CLIinterface.new}
it "once" do
# have and_return return the stub, not the symbol
expect(unit).to receive(:gets).and_return(units_input).once
# call the method
unit.units_inputs
# check that the instance variable is set
expect(unit.instance_method_get(:@units_input)).to eq(units_input)
end
私は擬似以下の肴サイトを試してみましたが、上記スローしました:
Failures:
1) units_inputs once
Failure/Error: unit.units_inputs
# <Double "metric"> received unexpected message :strip with (no args)
# ./cli.rb:14:in `units_inputs'
# ./spec/cli_spec.rb:11:in `block (2 levels) in <top (required)>'
ご質問はありますか? – sawa
申し訳ありませんが、前に入力したすべてのテキストは保存されませんでした。私は私が持っているステートメント/質問を再追加しました。私の欠陥を指摘していただきありがとうございます。 – bRRRITSCOLD
Rspecでユーザーの入力を模倣する方法を探していますか? – sawa