2016-02-12 163 views
0

我創建一個Rails應用程序,只是增加了一個文件(應用/規格/型號/ test_spec.rb )5個新RSpec的測試:爲什麼這些rspec測試「等待」?

describe Topic do 
    describe "scopes" do 

    before do 
     @public_topic = Topic.create # default is public 
     @private_topic = Topic.create(public: false) 
    end 

    describe "publicly_viewable" do 
     it "returns a relation of all public topics" do 
     expect(Topic.publicly_viewable).to eq([@public_topic]) 
     end 
    end 

    describe "privately_viewable" do 
     it "returns a relation of all private topics" do 
     expect(Topic.privately_viewable).to eq([@private_topic]) 
     end 
    end 

    describe "visible_to(user)" do 
     it "returns all topics if the user is present" do 
     user = User.new 
     expect(Topic.visible_to(user)).to eq(Topic.all) 
     end 

     it "returns only public topics if user is nil" do 
     expect(Topic.visible_to(nil)).to eq(Topic.publicly_viewable) 
     end 
    end 
    end 
end 

當我在跑了 「rspec的規格」控制檯,我得到了以下的輸出:

在8.38秒(文件耗時1分40.84秒加載) 18例,1次失敗,完成5未決

爲什麼這些例子5「待處理」?

+0

'rspec spec'命令應該告訴您哪些測試正在等待處理。你確定他們是這些嗎? –

+0

另外,爲了什麼是值得的,我正在處理某個特定的功能,我喜歡只運行該部分的單元測試。因此,而不是'rspec spec',我會使用'rspec'spec/models/test_spec.rb'-fd'。然後,一旦我的單元測試通過,我會做全套裝,集成測試等。順便說一句,'-fd'給你很好的輸出格式。 – jvillian

+0

@jvillian - 感謝您的回覆。當我運行'rspec'spec/models/test_spec.rb'-fd'時,我得到這個輸出:_/home/nitrous/code/bloccit/spec/models/topic_spec.rb:1:在中:未初始化的常量Topic(NameError) from /home/nitrous/code/project/.bundle/gems/rspec-core-3.3.2/lib/rspec/core/configuration.rb:1327:in加載 from/home/nitrous /code/bloccit/.bundle/gems/rspec-core-3.3.2/lib/rspec/core/configuration.rb:1327:in load_spec_files from /home/nitrous/code/bloccit/.bundle/gems/ rspec-core -... _ –

回答

1

Rspec在spec/的其他子目錄中爲您自動創建規格。您正在運行整個spec/目錄中的規範,其中包括自動生成的控制器規格,視圖規格,路由規格等。這些規範都附帶待定示例。如果您只想運行此文件中的規格,請運行rspec spec/models/test_spec.rb

+0

感謝您的回覆!當我運行'rspec spec/models/test_spec.rb'時,得到如下輸出:_/home/nitrous/code/project/spec/models/topic_spec.rb:1:in :未初始化的常量Topic NameError) from /home/nitrous/code/project/.bundle/gems/rspec-core-3.3.2/lib/rspec/core/configuration.rb:1327:in從/ home/nitrous/code/bloccit加載 /.bundle/gems/rspec-core-3.3.2/lib/rspec/core/configuration.rb:1327:in load_spec_files中的塊 from /home/nitrous/code/bloccit/.bundle/gems/rspec-core- ... _ –

+0

看到我對OP的評論。 –