2012-12-21 25 views
5

Khi chạy một spec Tôi nhận được tất cả các đầu ra của giao dịch cơ sở dữ liệu cũng như:RSpec Tùy chọn để thử nghiệm ứng dụng ray

lee$ rspec spec/mailers/ 
Connecting to database specified by database.yml 
    (0.1ms) BEGIN 
    User Exists (0.7ms) SELECT 1 AS one FROM "users" WHERE "users"."email" = '[email protected]' LIMIT 1 
    User Exists (0.4ms) SELECT 1 AS one FROM "users" WHERE "users"."auth_token" = '8bF72xsaxsSsidLvA1uD9Q' LIMIT 1 
    SQL (2.3ms) INSERT INTO "users" ("auth_token", "created_at", "email", "first_name", "last_name", "password_digest", "password_reset_token", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) RETURNING "id" [["auth_token", "8bF70xsaEsSsidLvA1uD9Q"], ["created_at", Fri, 21 Dec 2012 14:55:40 UTC +00:00], ["email", "[email protected]"], ["first_name", nil], ["last_name", nil], ["password_digest", "$2a$10$KXKLprkU/Irp30LoB8M.DuSwLV9bq9P3C7hIAO4yNShPrDE.NmHU."], ["password_reset_token", nil], ["updated_at", Fri, 21 Dec 2012 14:55:40 UTC +00:00]] 
    (1.6ms) COMMIT 
    Rendered user_mailer/customer_sigup_confirmation.html.erb (0.8ms) 
    Rendered user_mailer/customer_sigup_confirmation.text.erb (0.4ms) 
. 

Finished in 0.41419 seconds 
1 example, 0 failures 

Randomized with seed 6071 

Vẫn còn rất nhiều tiếng ồn! Làm cách nào để vô hiệu hóa/giảm bớt nó?

Dưới đây là spec_helper của tôi nếu nó giúp.

require 'rubygems' 
require 'spork' 
#uncomment the following line to use spork with the debugger 
# require 'spork/ext/ruby-debug' 

Spork.prefork do 
    # Loading more in this block will cause your tests to run faster. However, 
    # if you change any configuration or code from libraries loaded here, you'll 
    # need to restart spork for it take effect. 

    # This file is copied to spec/ when you run 'rails generate rspec:install' 
    ENV["RAILS_ENV"] ||= 'test' 
    require File.expand_path("../../config/environment", __FILE__) 
    require 'rspec/rails' 
    require 'rspec/autorun' 
    require 'capybara/rspec' 
    require 'capybara/poltergeist' 

    Capybara.javascript_driver = :poltergeist 

    # Requires supporting ruby files with custom matchers and macros, etc, 
    # in spec/support/ and its subdirectories. 
    Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} 

    RSpec.configure do |config| 
    # ## Mock Framework 
    # 
    # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line: 
    # 
    # config.mock_with :mocha 
    # config.mock_with :flexmock 
    # config.mock_with :rr 

    # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures 
    config.fixture_path = "#{::Rails.root}/spec/fixtures" 

    # If you're not using ActiveRecord, or you'd prefer not to run each of your 
    # examples within a transaction, remove the following line or assign false 
    # instead of true. 
    config.use_transactional_fixtures = true 

    # If true, the base class of anonymous controllers will be inferred 
    # automatically. This will be the default behavior in future versions of 
    # rspec-rails. 
    config.infer_base_class_for_anonymous_controllers = false 

    # Run specs in random order to surface order dependencies. If you find an 
    # order dependency and want to debug it, you can fix the order by providing 
    # the seed, which is printed after each run. 
    #  --seed 1234 
    config.order = "random" 


    # Include Factory Girl syntax to simplify calls to factories 
    config.include FactoryGirl::Syntax::Methods 

    # Add Support Modules 
    # config.include LoginMacros 
    config.include MailerMacros 
    config.before(:each) { reset_email } 

    config.treat_symbols_as_metadata_keys_with_true_values = true 
    config.filter_run :focus => true 
    config.run_all_when_everything_filtered = true 

    end 

end 

Spork.each_run do 
    # This code will be run each time you run your specs. 
    FactoryGirl.reload 

    class ActiveRecord::Base 
    mattr_accessor :shared_connection 
    @@shared_connection = nil 

    def self.connection 
     @@shared_connection || retrieve_connection 
    end 
    end 

    # Forces all threads to share the same connection. This works on 
    # Capybara because it starts the web server in a thread. 
    ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection 

end 

Trả lời

2

Trong bạn khởi tạo môi trường để thử nghiệm (config/môi trường/test.rb), configure đúng mức logger:

config.logger.level = Logger::FATAL

1

phần của vấn đề có lẽ bắt nguồn từ Poltergeist được sử dụng làm tài xế Capybara javascript. Tôi gặp vấn đề tương tự khi sử dụng capybara-webkit. Hãy thử sử dụng cú pháp sau:

Capybara.register_driver :poltergeist_silent do |app| 
    Capybara::Poltergeist::Driver.new(app, :logger => nil) 
end 
Capybara.javascript_driver = :poltergeist_silent 

này sẽ đi vào spec_helper của bạn, thay thế dòng này: . Điều này có thể ngăn các thông điệp nhật ký đề cập đến hiển thị.

Tôi có cảm giác rằng các thông báo về cơ sở dữ liệu có thể đến từ Spork, vì tôi đã sử dụng Rspec rộng rãi mà không cần Spork và tôi không thấy các thông báo đó. Bạn có thể thử kiểm tra xem có tùy chọn nào cho Spork để tắt thông báo nhật ký/stdout không?

+0

Cảm ơn Batkins nhưng vẫn như nhau. Và có, tôi đã khởi động lại ứng dụng trước khi kiểm tra. Tôi sẽ tìm kiếm trong spork hoặc poltergeist nữa. – Lee

+0

Hãy thử dòng này: 'Capybara :: Poltergeist :: Driver.new (app,: stdout => nil)'. Đó là gợi ý cuối cùng của tôi, vì đó là cú pháp của capybara-webkit (có vẻ như nó phải là ': logger' thay vì': stdout' cho 'poltergeist', nhưng có lẽ tôi không chính xác). – Batkins

+0

Boo Hoo. Vẫn không có thay đổi. Tôi sẽ tiếp tục đào bới. TY – Lee

Các vấn đề liên quan