5

카피 바라의 방문 방법이 저에게 효과적이지 않기 때문에 무슨 일이 일어나는지 잘 모르겠습니다 만 간단한 테스트를받을 수 없습니다. 나는 this railscast on testing을 끝내려고 노력했다.카피 바라 방문 방법이 작동하지 않습니다.

Capybara가 로그인 페이지를 방문해야하는 시점까지 가면 내 root_url 만 방문 할 수 있기 때문에 테스트가 실패합니다. 실패는 다음과 같습니다. 그것은 로그인 페이지를 방문 할 수 없기 때문에 실패합니다. 홈페이지에 붙어 점점 :

Running: spec/requests/password_resets_spec.rb 
Running tests with args ["--color", "--failure-exit-code", "2", "--format", "progress", "--format", "Guard::RSpec::Formatter::NotificationRSpec", "--out", "/dev/null", "--require", "/Users/lee/.rvm/gems/[email protected]_side/gems/guard-rspec-0.6.0/lib/guard/rspec/formatters/notification_rspec.rb", "spec/requests/password_resets_spec.rb"]... 
<!DOCTYPE html> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
<title>Home | My App</title> 
<link href="/assets/application.css" media="all" rel="stylesheet" type="text/css"> 
<script src="/assets/application.js" type="text/javascript"></script> 
</head> 
<body> 
    <ul class="user_nav"> 
<li><a href="/signup">Sign up</a></li> 
     <li><a href="/login">log in</a></li> 
    </ul> 
<h1>Supply Side</h1> 
<p> 
    This is the home page for My App. 
</p> 

<h2>Visit the <a href="/secret">Secret Page</a>.</h2> 


</body> 
</html> 
F 

Failures: 

    1) PasswordResets emails user when requesting password reset 
    Failure/Error: click_link "Forgot Your Password?" 
    Capybara::ElementNotFound: 
     no link with title, id or text 'Forgot Your Password?' found 
    # (eval):2:in `click_link' 
    # ./spec/requests/password_resets_spec.rb:8:in `block (2 levels) in <top (required)>' 

Finished in 0.40915 seconds 
1 example, 1 failure 

Failed examples: 

rspec ./spec/requests/password_resets_spec.rb:4 # PasswordResets emails user when requesting password reset 
Done. 

가 나는 그것이 로그인 페이지에 그것을 만들기 아니에요 것을 보여주기 위해 인쇄 page.html을 추가했습니다.

gem 'rails', '3.2.0' 
gem 'heroku' 
gem 'jquery-rails' 
gem 'sorcery' 

group :production do 
    gem 'pg' 
end 

group :development, :test do 
    gem 'sqlite3' 
    gem 'rspec-rails' 
    gem 'factory_girl_rails' 
    gem 'capybara' 
    gem 'guard-rspec' 
    gem 'spork' 
    gem 'guard-spork' 
    gem 'rb-fsevent' 
    gem 'wirble' 
end 

group :assets do 
    gem 'sass-rails', '~> 3.2.3' 
    gem 'coffee-rails', '~> 3.2.1' 
    gem 'uglifier', '>= 1.0.3' 
end 

내 경로 :

get "logout" => "sessions#destroy", :as => "logout" 
    get "login" => "sessions#new", :as => "login" 
    get "signup" => "users#new", :as => "signup" 
    resources :users do 
    member do 
     get :activate 
    end 
    end 
    resources :sessions 
    match "/forgot_password" => "sessions#forgot_password" 
    resources :password_resets 
    match "/secret" => "pages#secret" 
    root :to => "pages#home" 

여기

require 'rubygems' 
require 'spork' 

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 'capybara/rspec' 

    # 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| 
    config.mock_with :rspec 

    # 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 

    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 
end 

내 gemfile입니다 : 여기
require 'spec_helper' 

describe "PasswordResets" do 
    it "emails user when requesting password reset" do 
    user = Factory(:user) 
    visit login_path 
    print page.html 
    click_link "Forgot Your Password?" 
    fill_in "Email", :with => user.email 
    click_button "Reset Password" 
    end 
end 

내 사양/spec_helper.rb입니다 : 다음과 같은 테스트가 어떻게 표시되는지를 보여줍니다 그리고 마지막으로 내 config/environments/test.rb

# Settings specified here will take precedence over those in config/application.rb 

    # The test environment is used exclusively to run your application's 
    # test suite. You never need to work with it otherwise. Remember that 
    # your test database is "scratch space" for the test suite and is wiped 
    # and recreated between test runs. Don't rely on the data there! 
    config.cache_classes = true 

    # Configure static asset server for tests with Cache-Control for performance 
    config.serve_static_assets = true 
    config.static_cache_control = "public, max-age=3600" 

    # Log error messages when you accidentally call methods on nil 
    config.whiny_nils = true 

    # Show full error reports and disable caching 
    config.consider_all_requests_local  = true 
    config.action_controller.perform_caching = false 

    # Raise exceptions instead of rendering exception templates 
    config.action_dispatch.show_exceptions = false 

    # Disable request forgery protection in test environment 
    config.action_controller.allow_forgery_protection = false 

    # Tell Action Mailer not to deliver emails to the real world. 
    # The :test delivery method accumulates sent emails in the 
    # ActionMailer::Base.deliveries array. 
    config.action_mailer.delivery_method = :test 

    # Raise exception on mass assignment protection for Active Record models 
    config.active_record.mass_assignment_sanitizer = :strict 

    # Print deprecation notices to the stderr 
    config.active_support.deprecation = :stderr 

    config.action_mailer.default_url_options = { :host => 'localhost:3000' } 

Ruby 1.9.3에서 Rails 3.2를 실행 중입니다. 왜 이것이 작동하지 않는지에 대한 손실이 있습니다. 미리 감사드립니다!

+0

테스트가 인쇄하는 html은 로그인 페이지가 아니라 내 홈페이지 용입니다. 로그인 경로가 유효한 경로 임에도 불구하고 login_path를 방문 할 수 없기 때문에 실패합니다. 이것은 또한 실패합니다 : 방문을 방문하십시오. current_path.should == "/ login" –

+0

나는 또한 테스트가 실패하게하는 세션이 열려 있는지 확인하려고 시도했지만,이 테스트는 문제가 아닌 것으로 나타납니다. https ://gist.github.com/1677202 –

+0

하지만이 테스트는 작동합니다 : https://gist.github.com/1677265 그래서 Capybara는 홈페이지의 링크를 사용하여 로그인 페이지로 성공적으로 이동할 수 있습니다. –

답변

2

테스트 로그에서 테스트가 visit_login_path를 실행하면 초기에 해당 작업을 수행하고 있지만 다시 홈페이지로 리디렉션되고 있습니까?

+0

나는이 앱을 너무 일찍 처리하여 모든 것을 다시 설치 했으므로 제대로 작동합니다. 나는 그것이 일종의 구성 문제라고 생각한다. 여기에 chiming 주셔서 감사합니다! –

+0

@Lee, 귀하가 게시 한 Google 그룹에 응답이 있습니다. 테스트중인 링크가 누락되었습니다. 과거에 발견 한 바와 같이, 문제를 발견하기 전에 항상 잘못된 것을 수행했다고 가정합니다. ;-) 나는 항상 테스트를 신뢰하지 않는다. 시험 합격을하고 휴식을 취하십시오. – Tass

+0

고맙습니다. 나는 누군가가 구글 그룹에서 반응했다는 것을 몰랐다. 나는 바보 같은 질문에 대해 나에게 머리를 줘서 고맙습니다. –