“给定我已登录”的黄瓜步骤定义 [英] Cucumber step definition for "Given that I'm logged in"

查看:147
本文介绍了“给定我已登录”的黄瓜步骤定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个黄瓜步骤:鉴于我已经登录



我不明白我应该如何实现它作为一个步骤定义。 p>

有人可能指向正确的方向,教程,博客等。

解决方案

 给定/ ^我有一个\s +用户 ] *)with email([^ \] *)and password([^ \] *)$ / do | username,email,password | 
@user = User.new (:email => email,
:username => username,
:password => password,
:password_confirmation => password)
@ user.save!
end

给定/ ^我是已认证的用户$ / do
name ='exmample'
email ='example@example.com'
我有一个用户#{name},电子邮件为#{email},密码为#{password}}
% {我去用户登录页面}
和%{我用#{name}填写user_username}
和%{我用#{password}填写user_password }
and%{I pressSign in}
end

原因我这样做,是我跑遍整个堆栈,并设置环境正常的用户的方式...


I've got a cucumber step: Given that I'm logged in

I don't understand how I should implement it as a step definition.

Could someone point me into right direction, tutorials, blogs etc.

解决方案

here is how I do it.

Given /^I have one\s+user "([^\"]*)" with email "([^\"]*)" and password "([^\"]*)"$/ do |username,email, password|
  @user = User.new(:email => email,
                   :username=>username,
                   :password => password,
                   :password_confirmation => password)
   @user.save!
end

Given /^I am an authenticated user$/ do
  name = 'exmample'
  email = 'example@example.com'
  password = 'secret!'

  Given %{I have one user "#{name}" with email "#{email}" and password "#{password}"}
  And %{I go to the user login page}
  And %{I fill in "user_username" with "#{name}"}
  And %{I fill in "user_password" with "#{password}"}
  And %{I press "Sign in"}
end

The reason I do it this way, is that I run through the entire stack and set the environment up the way a normal user would...

这篇关于“给定我已登录”的黄瓜步骤定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆