3

テストでサブドメインのユーザーをサインインさせることができません。

アップデート

再びセレヌイムをいじってみました。これで、test.log にこのエラーが記録されました。

PG::Error: ERROR:  deadlock detected
DETAIL:  Process 15762 waits for AccessExclusiveLock on relation 2994754 of database 2952965; blocked by process 15020.
Process 15020 waits for ShareLock on transaction 93977; blocked by process 15762.

spec_helper.rbと の両方rails s -e test -p 3001が別のトレッドでテスト データベースをいじっていて、それが postgresql を苦しめているのではないかと推測しています。

しかし、テスト環境で Rails サーバーを起動せずに、認証が必要なサブドメインで JavaScript をテストするにはどうすればよいでしょうか?

元の質問

この仕様は私に与えます

require 'spec_helper'
feature 'home' do

  let(:user)        {FactoryGirl.create(:user)}
  let!(:firm)       {user.firm} 
  let(:project)     {FactoryGirl.create(:project, firm:firm)}
  let(:statistics)  {"http://#{firm.subdomain}.lvh.me:3001/statistics"} 
  let(:timesheet)   {"http://#{firm.subdomain}.example.com/timesheets/#{user.id}"}
  let(:account)     {"http://#{firm.subdomain}.lvh.me:3001/account"}

    before(:each) do 
      login_as(user, :scope => :user, :domains => :all)  
    end

    scenario "Statistics" do 
     visit statistics
     page.should have_content("Stats for users")
     page.should have_content(user.name) 
    end 
    scenario 'account' do 
     visit account
      page.should have_content("Memeber since: ") 
    end
    scenario "Statistics select", js: true do
      login_as(user, :scope => :user, :domains => :all) 
      visit statistics
      page.should have_content(firm.name)
      page.should have_content(user.name)
      page.current_url.should == statistics
      page.select("Stats for projects", :from => "stats")
       save_and_open_page
      page.should have_content(project.name)
    end    
end

このエラー

..F   
Failures:

  1) home Statistics select
     Failure/Error: page.should have_content(firm.name)
       expected there to be text "name6" in "Please sign in. You need to sign in or register before continuing. Email Password Remember me Forgot your password?"
     # ./spec/features/home/statistics_spec.rb:30:in `block (2 levels) in <top (required)>'
     # ./spec/support/active_record.rb:13:in `block (3 levels) in <top (required)>'
     # ./spec/support/active_record.rb:12:in `block (2 levels) in <top (required)>'

Finished in 4.77 seconds
3 examples, 1 failure

私が使わないときは、js: trueすべてが順調です。ただし、poltergeist と phantomjs はログインできません。

spec_helper

require 'spork'
Spork.prefork do

  ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'database_cleaner'
require 'rspec/autorun'
require 'factory_girl'
require 'ruby-debug'
require 'capybara/rspec'
require 'capybara/poltergeist'
Capybara.javascript_driver = :poltergeist
include Warden::Test::Helpers
Warden.test_mode!

Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}

RSpec.configure do |config|
  config.include Devise::TestHelpers, :type => :controller

  config.extend ControllerMacros, :type => :controller
  config.include ControllerMacros, :type => :feature

  config.include RequestMacros, :type => :request
  config.mock_with :rspec

  config.use_transactional_examples = false
  config.use_transactional_fixtures = false
  config.before(:suite) do
    DatabaseCleaner.strategy = :truncation
  end

  config.before(:each) do
    DatabaseCleaner.start
  end

  config.after(:each) do
    DatabaseCleaner.clean
  end
  config.infer_base_class_for_anonymous_controllers = false
 end 

 Spork.each_run do
   FactoryGirl.reload  
 end
end
4

0 に答える 0