3

我无法让我的测试在子域上登录用户。

更新

我再次尝试使用 selenuim。现在我在 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.

我猜测 thespec_helper.rb和 therails 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