配置Rspec终端输出

时间:2016-06-13 10:04:39

标签: ruby-on-rails ruby rspec

我是Rspec的初学者,我发现了这样的终端输出。

enter image description here 它确实很乱,很难理解测试结果。

与官方教程中的输出不同。 enter image description here

我应该安装一些工具还是修改一些配置?

更新

zombie.rb

class Zombie
attr_accessor :name
    def initialize
        @name = 'Error_Ash'
    end
end

zombie_spec.rb

require "spec_helper"
require "zombie"

#give Class
describe Zombie do 

# example 
    it "is named Class_Ash"
    zombie = Zombie.new 
    zombie.name.should == "Ash"
end

错误消息

Coda:rspec_pra Coda$ rspec spec/lib/zombie_spec.rb --format doc
/Users/Coda/.rvm/gems/ruby-2.1.3@rails416/gems/rspec-support-3.4.1/lib/rspec/support.rb:87:in `block in <module:Support>': expected: "Ash" (RSpec::Expectations::ExpectationNotMetError)
     got: "Error_Ash" (using ==)
    from /Users/Coda/.rvm/gems/ruby-2.1.3@rails416/gems/rspec-support-3.4.1/lib/rspec/support.rb:96:in `call'
    from /Users/Coda/.rvm/gems/ruby-2.1.3@rails416/gems/rspec-support-3.4.1/lib/rspec/support.rb:96:in `notify_failure'
    from /Users/Coda/.rvm/gems/ruby-2.1.3@rails416/gems/rspec-expectations-3.4.0/lib/rspec/expectations/fail_with.rb:27:in `fail_with'
    from /Users/Coda/.rvm/gems/ruby-2.1.3@rails416/gems/rspec-expectations-3.4.0/lib/rspec/matchers/built_in/operators.rb:71:in `fail_with_message'
    from /Users/Coda/.rvm/gems/ruby-2.1.3@rails416/gems/rspec-expectations-3.4.0/lib/rspec/matchers/built_in/operators.rb:106:in `__delegate_operator'
    from /Users/Coda/.rvm/gems/ruby-2.1.3@rails416/gems/rspec-expectations-3.4.0/lib/rspec/matchers/built_in/operators.rb:91:in `eval_match'
    from /Users/Coda/.rvm/gems/ruby-2.1.3@rails416/gems/rspec-expectations-3.4.0/lib/rspec/matchers/built_in/operators.rb:51:in `block in use_custom_matcher_or_delegate'
    from /Users/Coda/Desktop/code/ruby_pra/rspec_pra/spec/lib/zombie_spec.rb:11:in `block in <top (required)>'
    from /Users/Coda/.rvm/gems/ruby-2.1.3@rails416/gems/rspec-core-3.4.4/lib/rspec/core/example_group.rb:385:in `module_exec'
    from /Users/Coda/.rvm/gems/ruby-2.1.3@rails416/gems/rspec-core-3.4.4/lib/rspec/core/example_group.rb:385:in `subclass'
    from /Users/Coda/.rvm/gems/ruby-2.1.3@rails416/gems/rspec-core-3.4.4/lib/rspec/core/example_group.rb:255:in `block in define_example_group_method'
    from /Users/Coda/.rvm/gems/ruby-2.1.3@rails416/gems/rspec-core-3.4.4/lib/rspec/core/dsl.rb:43:in `block in expose_example_group_alias'
    from /Users/Coda/.rvm/gems/ruby-2.1.3@rails416/gems/rspec-core-3.4.4/lib/rspec/core/dsl.rb:82:in `block (2 levels) in expose_example_group_alias_globally'
    from /Users/Coda/Desktop/code/ruby_pra/rspec_pra/spec/lib/zombie_spec.rb:6:in `<top (required)>'
    from /Users/Coda/.rvm/gems/ruby-2.1.3@rails416/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1361:in `load'
    from /Users/Coda/.rvm/gems/ruby-2.1.3@rails416/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1361:in `block in load_spec_files'
    from /Users/Coda/.rvm/gems/ruby-2.1.3@rails416/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1359:in `each'
    from /Users/Coda/.rvm/gems/ruby-2.1.3@rails416/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1359:in `load_spec_files'
    from /Users/Coda/.rvm/gems/ruby-2.1.3@rails416/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:106:in `setup'
    from /Users/Coda/.rvm/gems/ruby-2.1.3@rails416/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:92:in `run'
    from /Users/Coda/.rvm/gems/ruby-2.1.3@rails416/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:78:in `run'
    from /Users/Coda/.rvm/gems/ruby-2.1.3@rails416/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:45:in `invoke'
    from /Users/Coda/.rvm/gems/ruby-2.1.3@rails416/gems/rspec-core-3.4.4/exe/rspec:4:in `<top (required)>'
    from /Users/Coda/.rvm/gems/ruby-2.1.3@rails416/bin/rspec:22:in `load'
    from /Users/Coda/.rvm/gems/ruby-2.1.3@rails416/bin/rspec:22:in `<main>'
Coda:rspec_pra Coda$ 

1 个答案:

答案 0 :(得分:1)

如果spec_helper中没有任何内容以某种方式覆盖--format开关(我甚至不知道它是否可能),那么这应该给你通过的可读测试:

zombie.rb 与您发布完全一样,

<强> zombie_spec

require "spec_helper"
require "zombie"

describe Zombie do 
  it "is named Ash" do
    zombie = Zombie.new 
    expect(zombie.name).to eq "Ash"
  end
end

和命令rspec spec/lib/zombie_spec.rb -f d,它是--format documentation

的缩写

编辑*:哦对不起,你发布的错误确实是一个RSpec错误......它只是没有格式化,正如你所说的x.x 试试--tty标志吧? rspec spec/lib/zombie_spec.rb --tty -f d