2014-11-14 5 views
0

오이와 우리가 사용하는 레일 앱을 테스트하려고합니다. 데이터베이스에 이미 생성되어 저장되어있는 사용자로 로그인 할 때 다음과 같은 오류가 발생합니다.레일 애플리케이션의 오이 테스트가 사용자 로그인 용 양식을 제출하지 않는 것 같습니다.

그런 다음 로그인 오류 메시지 # features/step_definitions/user_steps가 표시됩니다. RB는 16 는 "환영 admin"을 포함하는 다음과 같은 요소의 내용을 예상 : 그 얻지 못한으로, 대신 유효하지 않은 세부 사항에 사용자 로그인 실패의 사용자가 로그인 할 때 얻을 수있는 코드를 변경

Csa 
     Welcome Guest 
     Forgot password? 
     or 
     Register 
     HomeJobs 
     English 
    Cymraeg 
    Welcome to CS-Alumni News 
    The is where the home page text will go. 
    (RSpec::Expectations::ExpectationNotMetError) 
    ./features/step_definitions/user_steps.rb:18:in `/^I see a login error message$/' 
    features/users/login.feature:9:in `Then I see a login error message' 

작동하지 않았고, 플래시 메시지를받지 않았기 때문에 그것이 아닌지 확신 할 수 없었습니다. 여기

는 step_definitions 파일 (user_steps.rb) 여기서
require 'webrat' 

Given /^I do not have an account$/ do 
    @user = FactoryGirl.create(:user) 
    @user ||= User.where(:email >= @user[:email]).first 
    @user.destroy unless @user.nil? 
end 

When /^I attempt to login with my details$/ do 
    visit new_session_path 
    fill_in "login-input", :with => "admin" 
    fill_in "password", :with => "taliesin" 
    clicks_button "Login" 
end 

Then /^I see a login error message$/ do 
    visit home_path 
    response.should contain("Welcome admin") 
end 

And /^I should not be logged in$/ do 
    #response.should_not contain("Welcome admin") 
end 

가 login.feature 파일이다 : 여기
Feature: Login 
    In order to access my account 
    As a user 
    I want to be able to login 

     Scenario: User does not have an account 
      Given I do not have an account 
      When I attempt to login with my details 
      Then I see a login error message 
      And I should not be logged in 

     Scenario: User enters incorrect Login 
      Given I have an account 
      And I am not logged in 
      When I enter an incorrect Login 
      Then I see a login error message 
      And I should not be logged in 

     Scenario: User enters incorrect password 
      Given I have an account 
      And I am not logged in 
      When I enter an incorrect password 
      Then I see a login error message 
      And I should not be logged in 

     Scenario: User logs in successfully 
      Given I have an account 
      And I am not logged in 
      When I enter my correct login 
      And I enter my correct password 
      Then I see a successful login message 
      When I return to the application 
      Then I should still be logged in 

가 env.rb 파일이고; 여기
require 'cucumber/rails' 
require 'webrat' 
require 'cucumber/rails/world' 
require 'webrat/core/matchers' 

Webrat.configure do |config| 
config.mode = :rack 
config.open_error_files = false 
end 

World(Webrat::Methods) 
World(Webrat::Matchers) 

ActionController::Base.allow_rescue = false 


begin 
    DatabaseCleaner.strategy = :transaction 
    rescue NameError 
    raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish    to use it." 
    end 

Cucumber::Rails::World.use_transactional_fixtures = false 

class ActiveSupport::TestCase 
setup do |session| 
session.host! "localhost:3001" 
end 
end 

rails/blob/master/features/choose_javascript_database_strategy.feature 
Cucumber::Rails::Database.javascript_strategy = :truncation 

는 gemfile입니다 :

# Use jquery as the JavaScript library 
gem "jquery-rails", "~> 2.3.0" 
gem 'jquery-ui-rails', '4.1.2' 

# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks 
gem 'turbolinks' 

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder 
gem 'jbuilder', '~> 1.2' 

group :doc do 
    # bundle exec rake doc:rails generates the API under doc/api. 
    gem 'sdoc', require: false 
    end 

group :development, :test do 
    gem 'rspec-rails', '~> 3.0.0' 
    gem 'cucumber-rails', require: false 
    gem "webrat" 
    gem 'factory_girl_rails' 
    gem 'selenium-client' 
    gem 'capybara' 
    gem 'database_cleaner' 
end 

답변

0

이 좋아, 그래서 당신의 단계는 이것이다 :

Then /^I see a login error message$/ do 
    visit home_path 
    response.should contain("Welcome admin") 
end 

그리고 당신이지고있는 오류는 다음과 같습니다 RSpec::Expectations::ExpectationNotMetError

나는 생각한다 그것은 단지 여러분이 기대가 잘못되었다는 것이지만 적어도 약간 오도하는 것입니다. 우리는 실제로 "로그인 할 수 없음"과 같은 오류를보아야하지만 환영 메시지와 같이 보이는 "Welcome admin"을 찾고 있습니다.

무엇이 렌더링되고 있는지 예상하기 전에 puts response.body을 배치하여 디버깅 할 수 있습니다.

오이가 요청을 기다리는 중일 수도 있습니다. find('#some-element')을 추가하면 몇 초 기다려서 요소를 찾을 수 없으면 실패 할 수 있습니다.

편집 : 또한 내가 실행 한 기능이 사용자가 포함 된 것이 아니기 때문에 (login.feature) 잘못된 로그인을 시도하지 않고 오류 메시지를 보려고합니다.

+0

감사합니다. 지금 분류되었습니다. –