testing - Ruby TypeError: no implicit conversion of String into Array -
i have test returns typeerror: no impliciit conversion of string array
, when hits section of code. if run code outside of rspec runs fine, i'm not sure why happening.
require 'spec_helper' require 'digital_ocean_size_list' describe chef::knife::digitaloceansizelist subject { chef::knife::digitaloceansizelist.new } let(:access_token) { 'fake_access_token' } before :each chef::knife::digitaloceansizelist.load_deps chef::config['knife']['digital_ocean_access_token'] = access_token allow(subject).to receive(:puts) end describe "#run" "should validate digital ocean config keys exist" expect(subject).to receive(:validate!) subject.run end ....
it's testing next code
require 'chef/knife/digital_ocean_base' class chef class knife class digitaloceansizelist < knife include knife::digitaloceanbase banner 'knife digital_ocean size list (options)' def run $stdout.sync = true validate! size_list = [ ui.color('slug', :bold) ] client.sizes.all.each |size| size_list << size.slug.to_s end puts ui.list(size_list, :uneven_columns_across, 1) end end end end
the type error coming client.sizes.all.each. code runs fine, type error when it's rspec.
change
size_list << size.slug.to_s
to
size_list << [size.slug.to_s]
in case, error occurred because value had set array doesn't have []
, wrap []
, works.
ruby testing rspec
No comments:
Post a Comment