2016-06-13 103 views
0

我是一個初學者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/[email protected]/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/[email protected]/gems/rspec-support-3.4.1/lib/rspec/support.rb:96:in `call' 
    from /Users/Coda/.rvm/gems/[email protected]/gems/rspec-support-3.4.1/lib/rspec/support.rb:96:in `notify_failure' 
    from /Users/Coda/.rvm/gems/[email protected]/gems/rspec-expectations-3.4.0/lib/rspec/expectations/fail_with.rb:27:in `fail_with' 
    from /Users/Coda/.rvm/gems/[email protected]/gems/rspec-expectations-3.4.0/lib/rspec/matchers/built_in/operators.rb:71:in `fail_with_message' 
    from /Users/Coda/.rvm/gems/[email protected]/gems/rspec-expectations-3.4.0/lib/rspec/matchers/built_in/operators.rb:106:in `__delegate_operator' 
    from /Users/Coda/.rvm/gems/[email protected]/gems/rspec-expectations-3.4.0/lib/rspec/matchers/built_in/operators.rb:91:in `eval_match' 
    from /Users/Coda/.rvm/gems/[email protected]/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/[email protected]/gems/rspec-core-3.4.4/lib/rspec/core/example_group.rb:385:in `module_exec' 
    from /Users/Coda/.rvm/gems/[email protected]/gems/rspec-core-3.4.4/lib/rspec/core/example_group.rb:385:in `subclass' 
    from /Users/Coda/.rvm/gems/[email protected]/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/[email protected]/gems/rspec-core-3.4.4/lib/rspec/core/dsl.rb:43:in `block in expose_example_group_alias' 
    from /Users/Coda/.rvm/gems/[email protected]/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/[email protected]/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1361:in `load' 
    from /Users/Coda/.rvm/gems/[email protected]/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1361:in `block in load_spec_files' 
    from /Users/Coda/.rvm/gems/[email protected]/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1359:in `each' 
    from /Users/Coda/.rvm/gems/[email protected]/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1359:in `load_spec_files' 
    from /Users/Coda/.rvm/gems/[email protected]/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:106:in `setup' 
    from /Users/Coda/.rvm/gems/[email protected]/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:92:in `run' 
    from /Users/Coda/.rvm/gems/[email protected]/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:78:in `run' 
    from /Users/Coda/.rvm/gems/[email protected]/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:45:in `invoke' 
    from /Users/Coda/.rvm/gems/[email protected]/gems/rspec-core-3.4.4/exe/rspec:4:in `<top (required)>' 
    from /Users/Coda/.rvm/gems/[email protected]/bin/rspec:22:in `load' 
    from /Users/Coda/.rvm/gems/[email protected]/bin/rspec:22:in `<main>' 
Coda:rspec_pra Coda$ 
+1

由於zombie_spec.rb在第12行(未初始化的常量)中的語法錯誤,rspec失敗。它沒有達到的地方 - 格式開關會給你很好的輸出:) 編輯:如果你發佈完整的錯誤輸出,規範代碼,我們可能能夠解決這個問題;) – Ninigi

+0

我修改了一些代碼並重新發布第一張照片,我已經把代碼放在上面。非常感謝。 –

+0

嗯,不知道這是否相關,但'something.should =='表示法已被棄用。您應該使用'expect(zombie.name).to eq「Ash」'來代替。 而它的塊是缺少的;) – Ninigi

回答

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 WHI ch是--format documentation的簡稱

編輯*:哦,對不起,您發佈的錯誤確實是一個RSpec錯誤...它只是沒有格式化,如您所說x.x 試試--tty標誌也許? rspec spec/lib/zombie_spec.rb --tty -f d

+0

看來,我想念那塊。我添加'do'&'end',它工作。但我應該真正修改它以「預期」。謝謝。 –