我有一个ruby 脚本,它在运行时从用户那里获取书籍的价格。我是为 Ruby 脚本编写 RSpec 测试的新手。我正在使用 Ruby 1.9.3-p327 和 rspec 2.11.0。你可以从Github这个链接克隆我的项目。
我的 Rspec 测试旨在测试新实例化的对象是否属于特定类。
如果我在ruby 脚本中注释第 32 行,我的测试成功通过。
不知何故,当我取消注释该行时,我收到下面的错误,这与用户输入有关。我什至没有将它作为我的规范文件的一部分进行测试,但我仍然遇到了这个错误。我不确切知道为什么以及如何解决这个问题。
The Last Samurai: /home/mohnish/xxx/yyy/sample_pocs/book/book.rb:11:in `gets': Is a directory - spec (Errno::EISDIR)
from /home/mohnish/xxx/yyy/sample_pocs/book/book.rb:11:in `gets'
from /home/mohnish/xxx/yyy/sample_pocs/book/book.rb:11:in `block in get_prices'
from /home/mohnish/xxx/yyy/sample_pocs/book/book.rb:9:in `each'
from /home/mohnish/xxx/yyy/sample_pocs/book/book.rb:9:in `inject'
from /home/mohnish/xxx/yyy/sample_pocs/book/book.rb:9:in `get_prices'
from /home/mohnish/xxx/yyy/sample_pocs/book/book.rb:49:in `<top (required)>'
from /home/mohnish/xxx/yyy/sample_pocs/book/spec/spec_helper.rb:1:in `require_relative'
from /home/mohnish/xxx/yyy/sample_pocs/book/spec/spec_helper.rb:1:in `<top (required)>'
from /home/mohnish/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /home/mohnish/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /home/mohnish/xxx/yyy/sample_pocs/book/spec/book_spec.rb:1:in `<top (required)>'
from /home/mohnish/.rvm/gems/ruby-1.9.3-p327@book_set/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `load'
from /home/mohnish/.rvm/gems/ruby-1.9.3-p327@book_set/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `block in load_spec_files'
from /home/mohnish/.rvm/gems/ruby-1.9.3-p327@book_set/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `map'
from /home/mohnish/.rvm/gems/ruby-1.9.3-p327@book_set/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `load_spec_files'
from /home/mohnish/.rvm/gems/ruby-1.9.3-p327@book_set/gems/rspec-core-2.11.1/lib/rspec/core/command_line.rb:22:in `run'
from /home/mohnish/.rvm/gems/ruby-1.9.3-p327@book_set/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:69:in `run'
from /home/mohnish/.rvm/gems/ruby-1.9.3-p327@book_set/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:8:in `block in autorun'
我还想测试此示例的用户输入。如果你能阐明我怎么能得到同样的结果,那就太好了。我找到了一些可以开始测试用户输入的地方,例如 1和2,但我主要是在寻找如何测试用户输入的一些属于哈希的元素
谢谢。