Rsepc-rails输出Capybarra学习的最佳实践

时间:2015-06-08 08:35:51

标签: ruby-on-rails-4 rspec-rails

当我运行模型时,创建rspec会创建大量空测试。我一直在努力学习,并一直在创建自己的功能/ .specs。这让我得到如下的输出。我应该只是在这些文件中编写测试吗? helper_specs是什么?或者你可以抑制帮助者的警告?我曾尝试将 require'capybara / rspec' 添加到其中一个视图/ .specs中,但它似乎不起作用。

D:\Workspace\FrogDB>rspec
DL is deprecated, please use Fiddle
......*****

Pending: (Failures listed here are expected and do not affect your suite's status)

  1) HomepageHelper add some examples to (or delete) D:/Workspace/FrogDB/spec/helpers/homepage_helper_spec.rb
     # Not yet implemented
     # ./spec/helpers/homepage_helper_spec.rb:14

  2) StaticPagesHelper add some examples to (or delete) D:/Workspace/FrogDB/spec/helpers/static_pages_helper_spec.rb
     # Not yet implemented
     # ./spec/helpers/static_pages_helper_spec.rb:14

  3) homepage/index.html.erb add some examples to (or delete) D:/Workspace/FrogDB/spec/views/homepage/index.html.erb_spec.rb
     # Not yet implemented
     # ./spec/views/homepage/index.html.erb_spec.rb:4

  4) static_pages/about.html.erb add some examples to (or delete) D:/Workspace/FrogDB/spec/views/static_pages/about.html.erb_spec.rb
     # Not yet implemented
     # ./spec/views/static_pages/about.html.erb_spec.rb:4

  5) static_pages/contact.html.erb add some examples to (or delete) D:/Workspace/FrogDB/spec/views/static_pages/contact.html.erb_spec.rb
     # Not yet implemented
     # ./spec/views/static_pages/contact.html.erb_spec.rb:4


Finished in 0.18501 seconds (files took 9 seconds to load)
11 examples, 0 failures, 5 pending

我的第一个简单测试。 的规格/特征/ static_pages_spec.rb

require 'spec_helper'
require 'capybara/rspec'

describe "the static_Pages should have the correct content" do
  describe "check on ABOUT page" do
    before { visit static_pages_about_path}
    it "should have the correct About content" do
      expect(page).to have_text("StaticPages#about")
    end
  end
  describe "check on Contact" do
    before { visit static_pages_contact_path}
    it "should have the correct CONTACT content" do
      expect(page).to have_text("StaticPages#contact")
    end
  end
end

如果我重写 views / static_pages / about.html.erb_spec.rb ,则无法识别capybara命令 expect(page).to < / strong>

 require 'spec_helper'
    require 'capybara/rspec'

    describe "the static_Pages should have the correct content" do
      describe "check on ABOUT page" do
     #   before { visit static_pages_about_path}
        it "should have the correct About content" do
          expect(page).to have_text("StaticPages#about")
        end
      end
end

0 个答案:

没有答案