2014-11-13 3 views
0

Я проверил все предыдущие вопросы и весь Google для ответа на этот вопрос, но все еще не решил.Получение ошибки «неопределенной локальной переменной или метода» при методе посещения при попытке использовать webrat для моих тестов огурца

Я получаю следующее сообщение об ошибке при выполнении моих огурца тестов:

ps.rb:1 
    When I attempt to login with my details 
    # features/step_definitions/user_steps.rb:7 
    undefined local variable or method `new_session' for #<Cucumber::Rails::World:0x007ff5943e0620> (NameError) 
    ./features/step_definitions/user_steps.rb:8:in 
    /^I attempt to login with my details$/ 
    features/users/login.feature:8:in `When I attempt to login with my details 

И вот результат испытаний:

Failing Scenarios: 
cucumber features/users/login.feature:6 
# Scenario: User does not have an account 

6 scenarios (1 failed, 5 undefined) 
30 steps (1 failed, 6 skipped, 22 undefined, 1 passed) 
0m0.763s 

Это происходит сбой при посещении new_session

Здесь это все в моем файле env.rb (features/support/env.rb):

require 'cucumber/rails' 
require 'webrat' 
require 'webrat/core/matchers' 

Webrat.configure do |config| 
    config.mode = :rack 
    config.open_error_files = false # Set to true if you want error pages to pop up in the browser 
end 

ActionController::Base.allow_rescue = false 

# Remove/comment out the lines below if your app doesn't have a database. 
# For some databases (like MongoDB and CouchDB) you may need to use :truncation instead. 
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 

# Possible values are :truncation and :transaction 
# The :transaction strategy is faster, but might give you threading problems. 
# See https://github.com/cucumber/cucumber-rails/blob/master/features/choose_javascript_database_strategy.feature 
Cucumber::Rails::Database.javascript_strategy = :truncation 

Вот мой Gemfile:

gem 'thin' 

gem 'paperclip', '~> 4.1' 

gem 'simple-navigation' 

gem 'will_paginate', '~> 3.0' 

# Required by Windows and some Linux platforms when running with Rails 4.1.5! 
gem 'tzinfo-data' 

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' 
gem 'rails', '4.1.5' 

# Use sqlite3 as the database for Active Record 
gem 'sqlite3' 

# Use SCSS for stylesheets 
gem 'sass-rails', '~> 4.0.3' 

# Use Uglifier as compressor for JavaScript assets 
gem 'uglifier', '>= 1.3.0' 

# Use CoffeeScript for .js.coffee assets and views 
gem 'coffee-rails', '~> 4.0.0' 

gem 'oauth', '~>0.4.6' 

# See https://github.com/sstephenson/execjs#readme for more supported runtimes 
# gem 'therubyracer', platforms: :ruby 

# 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 'capybara' 
    gem 'database_cleaner' 
end 

Вот файл user_steps.rb (функции/step_definitons/user_steps.rb):

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 
    fill_in "login", :with => "invalid_login" 
    fill_in "password", :with => "invalid_password" 
    click_button "commit" 
end 

Then /^I see a login error message$/ do 
    response.should contain("Couldn't log you in as invalid_login") 
end 

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

Here is the feature, in the login.features file (features/users/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 

Вот мои маршруты:

Prefix Verb URI Pattern    Controller#Action 
search_users GET /users/search(.:format) users#search 
     users GET /users(.:format)   users#index 
       POST /users(.:format)   users#create 
    new_user GET /users/new(.:format)  users#new 
    edit_user GET /users/:id/edit(.:format) users#edit 
     user GET /users/:id(.:format)  users#show 
       PATCH /users/:id(.:format)  users#update 
       PUT /users/:id(.:format)  users#update 
       DELETE /users/:id(.:format)  users#destroy 
    broadcasts GET /broadcasts(.:format)  broadcasts#index 
       POST /broadcasts(.:format)  broadcasts#create 
new_broadcast GET /broadcasts/new(.:format) broadcasts#new 
    broadcast GET /broadcasts/:id(.:format) broadcasts#show 
       DELETE /broadcasts/:id(.:format) broadcasts#destroy 
     session POST /session(.:format)  sessions#create 
    new_session GET /session/new(.:format) sessions#new 
       DELETE /session(.:format)  sessions#destroy 
     home GET /home(.:format)   home#index 
     root GET /      home#index 

ответ

0

Я думаю, вы хотите вызвать метод helper метода, который будет генерировать URL-адрес вашей страницы входа.

Методы методов маршрута должны заканчиваться _path или _url.

Таким образом, вы должны заменить new_session на new_session_path в своих определениях шагов.

+0

Большое спасибо, что исправил эту проблему, просто имея дело с другими ошибками, которые возникают сейчас: p Я не думаю, что вы знаете, что я могу сделать с этим: –

+0

undefined method 'use_ssl 'для # < Rails :: Application :: Configuration: 0x007f86f3d87198> (ActionController :: RoutingError) ./config/initializers/force_ssl_extension.rb:5:in 'force_ssl ' ./app/controllers/sessions_controller.rb::in' <класс : SessionsController> ' ./app/controllers/sessions_controller.rb:1:in '' ./features/step_definitions/user_steps.rb:10:in'/^ Я пытаюсь войти с моими данными $/' –

+0

Создайте новый вопрос по другой проблеме и укажите более подробную информацию/код. –