4

多くの統合テストで Capybara を動作させることができません。

特定のページにアクセスすると、次の html が表示されます。

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">

have_content()そのため、セレクターを使用しようとすると、次のエラーが発生します。

 Failure/Error: page.should have_content("HELLO")
 Capybara::ElementNotFound:
   Unable to find xpath "/html"

アプリの一部のページには問題なくアクセスできますが、他のページにはアクセスできません。一部の場所では機能し、他の場所では機能しないページもあります。

require 'spec_helper'

describe HomeController do

  it "shows the website description" do
    visit root_path
    puts page.html.length # ==> 108 (no html)
    ...
  end
end



require 'spec_helper'

describe FlowsController do

  it "should do stuff" do
    visit root_path
    puts page.html.length # ==> 4459, works even if the exact same one didn't work in home_controller_spec! 
    visit flows_path
    puts page.html.length # ==> 3402, works
    visit new_user_session_path
    puts page.html.length # ==> 3330, works
    within("form#new_user") do
      fill_in 'Email', :with => 'email@example.com'
      fill_in 'Password', :with => 'password'
      click_on 'Sign in'
    end
    puts page.html.length # ==> 108, No html
  end
end

この投稿で、これは Capybara と webrat を同時に使用した場合に発生する可能性があるエラーであると読みました。しかし、私はwebratをまったく使用していませんが、それでもエラーが発生します...

これが私のGemfileです:

source 'https://rubygems.org'

gem 'rails', '3.2.6'

gem 'pg'
gem 'thin'
gem 'devise'

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'

  gem 'uglifier', '>= 1.0.3'
end

# Add rspec for testing
group :test, :development do
  gem "rspec-rails", "~> 2.0"
  gem "capybara"
  gem "factory_girl_rails"
end

gem 'jquery-rails'
4

1 に答える 1

5

Controller クラスの代わりに、説明する文字列を渡してみてください

describe "whatever" do
  ...
end
于 2012-11-30T11:58:31.297 に答える