我正在使用ruby和rspec来编写自动化测试用例和watir。
C:\Users\san\Dragon>gem list 'rspec'
*** LOCAL GEMS ***
rspec (3.4.0, 2.14.1)
rspec-core (3.4.3, 2.14.8)
rspec-expectations (3.4.0, 2.14.5)
rspec-mocks (3.4.1, 2.14.6)
rspec-support (3.4.1)
当我使用以下命令运行测试用例时。
C:\Users\san\Dragon>rspec -f spec\sampletest_spec.rb:65
我收到了这个错误
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-3.4.3/lib/rspec/core/formatters.rb:173:in `find_formatter': Formatter 'spec\sampletest_spec.rb:65' unknown - maybe you meant 'documentation' or 'progress'?. (ArgumentError)
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-.4.3/lib/rspec/core/formatters.rb:141:in `add'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-3.4.3/lib/rspec/core/configuration.rb:767:in `add_formatter'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-3.4.3/lib/rspec/core/configuration_options.rb:114:in `block in load_formatters_into'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-3.4.3/lib/rspec/core/configuration_options.rb:114:in `each'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-3.4.3/lib/rspec/core/configuration_options.rb:114:in `load_formatters_into'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-3.4.3/lib/rspec/core/configuration_options.rb:23:in `configure'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-3.4.3/lib/rspec/core/runner.rb:105:in `setup'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-3.4.3/lib/rspec/core/runner.rb:92:in `run'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-3.4.3/lib/rspec/core/runner.rb:78:in `run'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-3.4.3/lib/rspec/core/runner.rb:45:in `invoke'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-3.4.3/exe/rspec:4:in `<top (required)>'
from C:/Ruby193/bin/rspec:23:in `load'
from C:/Ruby193/bin/rspec:23:in `<main>'
同样出错
rspec spec\sampletest_spec.rb --format documentation
rspec --format spec\sampletest_spec.rb
答案 0 :(得分:2)
你搞砸了。当您传递测试文件的名称时,--format
/ -f
参数需要将格式描述本身传递给它。
我不知道为什么
存在问题rspec spec\sampletest_spec.rb --format documentation
这一定必须奏效。但无论如何,最简单的解决方案是在项目根目录中创建.rspec
文件,其中包含以下内容:
--format documentation
是的,唯一的一条线。创建此文件后,只需运行即可
rspec spec\sampletest_spec.rb
RSpec
将从此文件中读取配置并应用所需的格式。