コマンドプロンプトからrspecファイルを実行時に以下のエラーが出ていて困っています。
10
F.
Failures:
-
argv 引数が数字の場合
Failure/Error: expect(argv(['1'])).to eq(1 * 10)expected: 10
got: nil(compared using ==)
./sample_1_spec.rb:6:in `block (2 levels) in <top (required)>'
Finished in 0.00701 seconds (files took 0.53979 seconds to load)
2 examples, 1 failure
Failed examples:
rspec ./sample_1_spec.rb:5 # argv 引数が数字の場合
下記がsample_1_spec.rbファイルの内容です
require '../spec_helper.rb'
require './sample_1.rb'
describe 'argv' do
it "引数が数字の場合" do
expect(argv(['1'])).to eq(1 * 10)
end
it "引数が数字以外の場合" do
expect eq('error')
end
end
下記がsample_1.rbの内容です
def argv(argv)
if /\A\d+\z/ =~ argv[0]
puts argv[0].to_i * 10
else
puts 'error'
end
end
if FILE == $PROGRAM_NAME
puts argv ARGV
end
よろしくお願い致します。
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。