2011-03-18 109 views
2

我有一個非常小的新鮮的Rails 3應用程序。我正在使用RubyCAS-Client gem for Rails來對我們的CAS服務器進行身份驗證。 CAS客戶端正在工作,因爲我可以登錄和退出我的Web應用程序。使用Cucumber來測試RubyCAS客戶端

這裏是我的Gemfile:

source 'http://rubygems.org' 

gem 'rails', '3.0.5' 
gem 'mysql2' 
gem 'jquery-rails' 
gem 'nifty-generators' 
# Deploy with Capistrano 
# gem 'capistrano' 
gem 'rubycas-client' 
gem 'rubycas-client-rails', :git => "git://github.com/zuk/rubycas-client-rails.git" 

group :development, :test do 
    gem 'unicorn' 
    gem 'capybara' 
    gem 'cucumber' 
    gem 'cucumber-rails' 
    gem 'database_cleaner' 
    gem 'rspec' 
    gem 'rspec-rails' 
    gem 'launchy' 
    gem 'webrat' 
end 

這裏是我的黃瓜的東西:

# feature file 

Feature: Manage generic_pages 
    In order to view pages that are in the base controller(generic) 
    I want to visit them and see that they work 

    Scenario: Visit the home page 
    Given I am on the home page 
    Given I am logged in 
    Then I should see "Submit a nomination" 
    And I should see "Nominee's name" 
    And I should see "What are you nominating them for?" 
    And I should see "Why are you nominating them for this award?" 

# cas-client steps 

Given /^I am logged_in$/ do 
    CASClient::Frameworks::Rails::Filter.fake("homer") 
end 

我得到的錯誤是:

Given I am logged_in                  # features/step_definitions/casclient_steps.rb:1 
     uninitialized constant CASClient::Frameworks (NameError) 
     ./features/step_definitions/casclient_steps.rb:2:in `/^I am logged_in$/' 
     features/manage_nominations.feature:9:in `Given I am logged_in' 

所有的步驟通過(如果我刪除所有的Cas登錄要求)。如果我添加casclient gem的'require'行,「登錄」步驟也會通過,但其餘步驟都會失敗。出於某種原因,就好像Cucumber沒有從Gemfile中加載適當的寶石,因此CASClient模塊不適用於其環境。對需求行進行忽略就像解決問題的最終結果,但實際上並沒有解決除即時錯誤之外的其他任何問題。

假過濾器是你應該如何使用Cucumber及其同類來測試的。我無法弄清楚爲什麼這不起作用。

+0

非常感謝,你讓我知道如何嘲笑爲CAS登錄:'cASClient: :框架::導軌:: Filter.fake(「豪濱海「)' – 2012-12-20 10:20:28

回答

0

我就遇到了這個問題爲好,我設法通過手動執行

require 'casclient/frameworks/rails/filter' 
1

由於您使用的寶石「rubycas-客戶軌」來解決這個問題,你應該使用:

RubyCAS: :Filter.fake(「本壘打」)

無需有需要「casclient /框架/導軌/過濾器」