1

ユーザーがログに記録するシナリオ(admin)をテストしてから、さらにユーザーを作成しようとしています。

ログでは、コントロールがログインページに移動し、管理者ユーザーがログインし、コントロールが他のユーザー作成ページにリダイレクトされると、ログインフィルターが停止し、コントロールをログインページにリダイレクトすることがわかります。

キュウリの初心者なので、コードの品質が良くないため、ログインしたユーザーサービスをテストするためのガイドが役立ちます

これが私のシナリオです

Feature: Create user from LMS
  In order to create lms user with multiple groups
  As a author
  I want to create lms user with multipl groups

  Scenario: Add  new user with multiple groups
      Given the following user information
      And I am logged in as author "gulled" with password "thebest"
      When I request for new lms user creation
      Then the new user "user1" should be created

そしてここに定義があります

Given /^the following user information$/ do 
  # Factory(:login)
  # Factory(:author)
end

Given /^I am logged in as author "([^"]*)" with password "([^"]*)"$/ do |username, password|
  visit "account/login"
  fill_in "loginfield", :with => username   
  fill_in "password", :with => password
  click_button "submit_button"  
end

When /^I request for new lms user creation$/ do
  visit "/author_backend_lms/new_user"  
  fill_in "login_first_name", :with => ""
  fill_in "login_last_name", :with => ""
  fill_in "login_login", :with => ""
  fill_in "login_email", :with => ""
  fill_in "login_password_confirmation", :with => ""
  click_button "create_user_form_submit_button"
end

Then /^the new user "([^"]*)" should be created$/ do |user_login|
  login = Login.find_by_login user
  assert_no_nil login, "Record creation failed" 
end

「新しいlmsユーザー作成のリクエスト」で、lmsユーザー作成ページにアクセスしようとすると、コントロールはログインページにリダイレクトします。

これが私のテスト用の宝石リストです

gem "capybara", "1.1.1"
gem "cucumber", "1.1.0"
gem "cucumber-rails", "0.3.2"   
4

2 に答える 2

0

Cucumber を使用してこのようなことを行うより良い (IMO) 方法を示すサンプル プロジェクトがあります。私はそれがあなたが求めたガイダンスのいくつかを提供するかもしれないと思います

ここを参照

役に立つことを願っています

于 2013-01-21T20:40:27.520 に答える
0

Given the following user informationステップで事前に管理者ユーザーを作成していないように見えるため、And I am logged in as author "gulled" with password "thebest"ステップが失敗します。

save_and_open_pageメソッドを使用して、各ステップの後に何が起こっているかをデバッグしてみてください。

シナリオを次のように書き直します(不要な詳細が多すぎないようにします)。

Scenario: Add  new user with multiple groups
  Given I am logged in as an admin user
  When I request for new lms user creation
  Then a new user should be created 

http://aslakhellesoy.com/post/11055981222/the-training-wheels-cam-offをチェックして、より良いシナリオを作成する方法に関するアドバイスを確認してください。

編集

事前にユーザーを作成してログインするための私のプロジェクトの 1 つからの step_definitions の例を次に示します。

Given /^the user has an account$/ do
  @user = FactoryGirl.create( :user )
end

When /^the user submits valid signin information$/ do
  fill_in "user_email",    with: @user.email
  fill_in "user_password", with: @user.password 
  click_button "Sign in"
  page.should have_link('Logout', href: destroy_user_session_path)
end

インスタンス変数を使用すると、ユーザー ファクトリ オブジェクトがステップ間で永続化されます。またlogout、ステップの最後にリンクがあることを確認することで、サインインが実際に成功したことが保証されます。これがステップ定義の微調整に役立つことを願っています。

于 2013-01-13T14:01:00.463 に答える