- 浏览: 2079099 次
- 性别:
- 来自: NYC
文章分类
- 全部博客 (628)
- Linux (53)
- RubyOnRails (294)
- HTML (8)
- 手册指南 (5)
- Mysql (14)
- PHP (3)
- Rails 汇总 (13)
- 读书 (22)
- plugin 插件介绍与应用 (12)
- Flex (2)
- Ruby技巧 (7)
- Gem包介绍 (1)
- javascript Jquery ext prototype (21)
- IT生活 (6)
- 小工具 (4)
- PHP 部署 drupal (1)
- javascript Jquery sort plugin 插件 (2)
- iphone siri ios (1)
- Ruby On Rails (106)
- 编程概念 (1)
- Unit Test (4)
- Ruby 1.9 (24)
- rake (1)
- Postgresql (6)
- ruby (5)
- respond_to? (1)
- method_missing (1)
- git (8)
- Rspec (1)
- ios (1)
- jquery (1)
- Sinatra (1)
最新评论
-
dadadada2x:
user模型里加上 protected def email ...
流行的权限管理 gem devise的定制 -
Sev7en_jun:
shrekting 写道var pattern = /^(0| ...
强悍的ip格式 正则表达式验证 -
jiasanshou:
好文章!!!
RPM包rpmbuild SPEC文件深度说明 -
寻得乐中乐:
link_to其实就是个a标签,使用css控制,添加一个参数: ...
Rails在link_to中加参数 -
aiafei0001:
完全看不懂,不知所然.能表达清楚一点?
"$ is not defined" 的问题怎么办
http://drnicwilliams.com/2009/03/26/testing-outbound-emails-with-cucumber/
My testimonial for Cucumber still stands even in 2009. In fact I promise to let you know when I don’t think Cucumber is the bees-knees of integration testing. I love the step-by-step English instructions of user usage scenarios backed by a simple Ruby DSL for describing real actions on your application for each step.
For testing Rails apps, Cucumber defaults to using Webrat on top of Rails’ own integration sessions. With Webrat you actually test that your views match to your controller actions. If I click the “Submit” button, then it checks that it invokes an available action correctly. Before Cucumber I could appreciate the merit of Webrat alone, but the two tools combined are instant superheroes of my Rails development crime fighting team. That is, like any superhero TV show at least once every 30 minutes you find yourself saying “Thank you Mr Cucumber and your trusty sidekick Webrat, you’re my heroes”. (BTW, I’m not alone in this analogy)
Testing emails
But I wanted to test emails. More interestingly, emails containing links back into my application. Like an activation email on sign up.
Specifically, I wanted a cucumber scenario like this:
Scenario: Signup for new account Given I am on the signup form When I fill in "Email" with "drnic@mocra.com" And I press "Join" Then I should see "An activation email has been sent" And I should receive an activation email When I click the activation email link Then I should see "Your account is active"
Within this scenario there are 7 steps. Lines 2, 3, 4 and 7 match to steps from the generated webrat_steps.rb file when you install cucumber.
Line 1 also matches to a webrat step definition. But it requires that you define what “the signup form” maps to in your routes. So you need to update features/support/paths.rb to specify what “the signup form” url is:
module NavigationHelpers def path_to(page_name) case page_name when /the signup form/ signup_path end end end
So, that leaves us with lines 5 and 6.
email-spec plugin
I’m happy using the email-spec gem/plugin from Ben Mabey , who is also the lead maintainer of the awesome Cucumber TextMate bundle and did a wonderful presentation on Outside-In Development with Cucumber at the recent Mountain West RubyConf (lots of great videos available )
To install as a plugin:
script/plugin install git://github.com/bmabey/email-spec.git
Then add the following line to your *feature/support/env.rb* file:
require 'email_spec/cucumber'
Finally, the plugin comes with some bonus cucumber step definitions which wrap around lots of nice helpers:
script/generate email_spec
Using email-spec step definitions
Let’s ignore my desired lines 5 and 6 above and use the step definitions that we get with email-spec. We can replace the two lines with the following:
And I should receive an email When I open the email Then I should see "Please activate your new account" in the subject When I click the first link in the email
Update: The last line didn’t used to be in email-spec but it now is. I’ve removed the example from this article.
I did all this for an existing application and every line of the scenario tested positive/green. Yay!
Refactoring four steps into two
For the sake of demonstration, you now might want to refactor these four steps into two steps to keep your scenarios nice and readable.
That is, how can we convert these 4 steps into our original lines 5 and 6?
The quickest way is to copy and paste the lines and slap some quotes around the text:
Then /^I should receive an activation email$/ do |email| Then 'I should receive an email' When 'I open the email' Then 'I should see "Please activate your new account" in the subject' end When /^I click the activation email link$/ do When 'I click the first link in the email' end
That’s right, you can use Given
/When
/Then
as invocation methods as well as step definition methods. If you don’t pass these methods a do…end block then they will match/find/invoke a step rather than define a new one. Very cool.
Alternately, you could implement the two steps using the underlying email helper methods provided by the email-spec plugin:
Then /^I should receive an activation email$/ do unread_emails_for(current_email_address).size.should == 1 open_email(current_email_address) current_email.should have_subject(/Please activate your new account/)) end When /^I click the activation email link$/ do click_first_link_in_email end
Your choice.
Configuring current_email_address
All the email-spec helper methods assume that the “I” in the scenario has an email address. It uses a method current_email_address
for this.
You must change the current_email_address
method in the email_steps.rb
file to pull out email addresses from wherever they might be located within any given scenario.
For example, here is one definition of the method from one of my projects:
def current_email_address @email || (@current_user && @current_user.email) || "drnic@mocra.com" end
Summary
发表评论
-
Destroying a Postgres DB on Heroku
2013-04-24 10:58 939heroku pg:reset DATABASE -
VIM ctags setup ack
2012-04-17 22:13 3261reference ctags --extra=+f --e ... -
alias_method_chain方法在3.1以后的替代使用方式
2012-02-04 02:14 3302alias_method_chain() 是rails里的一个 ... -
一些快速解决的问题
2012-01-19 12:35 1476问题如下: 引用Could not open library ... -
API service 安全问题
2011-12-04 08:47 1388这是一个长期关注的课题 rest api Service的 ... -
Module方法调用好不好
2011-11-20 01:58 1354以前说,用module给class加singleton方法,和 ... -
一个ajax和rails交互的例子
2011-11-19 01:53 1911首先,这里用了一个,query信息解析的包,如下 https: ... -
Rails 返回hash给javascript
2011-11-19 01:43 2280这是一个特别的,不太正统的需求, 因为,大部分时候,ajax的 ... -
关于Rubymine
2011-11-18 23:21 2270开个帖子收集有关使用上的问题 前一段时间,看到半价就买了。想 ... -
ruby中和javascript中,动态方法的创建
2011-11-18 21:01 1246class Klass def hello(*args) ... -
textmate快捷键 汇总
2011-11-16 07:20 8153TextMate 列编辑模式 按住 Alt 键,用鼠标选择要 ... -
Ruby面试系列六,面试继续面试
2011-11-15 05:55 2031刚才受到打击了,充分报漏了自己基础不扎实,不肯向虎炮等兄弟学习 ... -
说说sharding
2011-11-13 00:53 1502这个东西一面试就有人 ... -
rails面试碎碎念
2011-11-12 23:51 1950面试继续面试 又有问ru ... -
最通常的git push reject 和non-fast forward是因为
2011-11-12 23:29 17228git push To git@github.com:use ... -
Rails 自身的many to many关系 self has_many
2011-11-12 01:43 2741简单点的 #注意外键在person上people: id ... -
Rails 3下的 in place editor edit in place
2011-11-12 01:20 951第一个版本 http://code.google.com/p ... -
Heroku 的诡异问题集合
2011-11-11 07:22 1700开个Post记录,在用heroku过程中的一些诡异问题和要注意 ... -
SCSS 和 SASS 和 HAML 和CoffeeScript
2011-11-07 07:52 12965Asset Pipeline 提供了内建 ... -
Invalid gemspec because of the date format in specification
2011-11-07 02:14 2128又是这个date format的错误。 上次出错忘了,记录下 ...
相关推荐
接着安装 Cucumber 本身 (`gem install cucumber`),以及 RSpec,因为 Cucumber 常与 RSpec 结合使用来提供断言功能 (`gem install rspec`)。此外,还需要安装 Watir 和 Watir-Webdriver 以进行浏览器自动化测试 (`...
Cucumber的核心理念是将测试描述为人类可读的故事,这些故事称为特性文件,通常使用Gherkin语法编写。Gherkin是一种业务领域特定的语言,它的设计目的是使非技术人员也能理解测试用例。在提供的压缩包中,gherkin-...
Cucumber 是一种流行的自动化测试工具,特别是在BDD(行为驱动开发)中,它允许开发者、测试人员和非技术人员使用自然语言编写可执行的规范。在Java项目中,Cucumber经常被用来验证软件功能是否按预期工作。然而,当...
Appium是一个跨平台的测试框架,允许使用Cucumber编写测试脚本来控制iOS和Android设备。通过这种方式,开发者可以模拟用户交互,检查应用程序的功能和性能。 **在WEB测试中的应用**: 在Web测试中,Cucumber可以与...
使用Cucumber-rust进行测试时,你可以通过Cargo命令运行测试集,框架会自动匹配并执行所有关联的Gherkin步骤。`cucumber-rust`还支持断言库、日志记录、调试选项以及测试报告生成,从而提供了一个全面的测试环境。 ...
此外,Cucumber还支持使用辅助工具(如Cucumber-JVM、Cuke4Duke等)将自然语言编写的测试用例自动转化为测试脚本,从而与实际的软件应用程序进行交互。这种测试脚本的自动执行,帮助团队在软件开发过程中快速发现不...
总之,cucumber jar 包是 Cucumber 测试框架的核心组成部分,使得开发者能够使用结构化自然语言进行自动化测试,提高了测试的可读性和可维护性,同时降低了非技术人员参与测试的门槛。通过合理使用 cucumber.jar 和...
在Java平台上使用Cucumber进行自动化测试,首先需要创建一个Maven工程,并在`pom.xml`文件中引入Cucumber的相关依赖。创建Cucumber项目的一个便捷方式是使用`cucumber-prototype` Maven插件。在终端中,导航至想要...
Cucumber是一个自动化测试工具,它属于行为驱动开发(BDD)的范畴。这个工具的特点是可以用自然语言来描述测试用例,因此...开发人员可以使用Cucumber进行公共方法的封装,而功能测试人员则可以专注于编写测试用例。
Cucumber是一个开源的BDD工具,它允许开发者使用一种名为Gherkin的简单语言编写可执行的测试用例。Gherkin语言的关键词包括Feature(特性)、Scenario(场景)、Given(给定)、When(当)、Then(那么)等。通过...
根据给出的部分内容,这本书不仅覆盖了基本的Cucumber使用方法,还包括了一些更为高级和专业的技巧和窍门,比如如何处理难以驾驭的测试套件,如何在多个服务器间进行扩展测试,甚至包括了针对嵌入式Arduino硬件项目...
Cucumber以其易读性著称,因为它允许用自然语言编写测试场景,使得非技术人员也能理解测试目标。 首先,Cucumber是基于Gherkin语法的,这是一种结构化的自然语言,用于描述软件的功能。它的基本结构包括Feature文件...
项目移至 LEARNINGWELL 内部 GITLAB 服务器Cucumber STDDTool 格式化程序将测试结果发送到 STDDTool 的 -formatter开始: 在您的 Gemfile 中: gem 'stddtool' 并在您的/support/env.rb文件或支持目录下的任何其他...
6. **数据层测试**: SpringBoot通常与Spring Data一起使用,我们可以用Cucumber测试数据库操作,比如验证保存、查询和删除数据的逻辑。 7. **断言库**: Cucumber测试中会使用JUnit或其他断言库(如AssertJ)来验证...
主要介绍了Springboot Cucumber测试配置介绍详解,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
- **验收测试**:客户或产品所有者可以使用Cucumber编写验收标准,确保软件满足业务需求。 - **文档化需求**:Cucumber的测试案例本身就是一种文档,可以作为项目需求的一部分,方便团队成员理解和追踪需求变化。 #...
Maven 搭建cucumber 简单示例 1.新建Maven 项目 2.Eclipse安装 cucumber 插件:Help->Install New Software->Add name:cucumber location:http://cucumber.github.com/cucumber-eclipse/update-site 3.导入示例项目,...
在,Jest-Cucumber-Fusion使用整齐的Cucumber样式来处理相应的Jest测试步骤。 您不必为每个场景编写一个Jest测试,而无需使用describe和it块,然后在Jest测试中定义Given , When和Then步骤定义。 然后,Jest-...
在Scala开发环境中,结合使用SBT(Simple Build Tool)构建工具,Cucumber可以帮助开发者编写易于理解的自然语言测试用例,从而实现更高效的沟通和协作。 ### 1. Cucumber的核心概念 - **Gherkin语言**:Cucumber...
在他们下载的chm始终打不开或有问题。 ... 使用Cucumber+Rspec玩转BDD(1)——用户注册 使用Cucumber+Rspec玩转BDD(2)——邮件激活 ...使用Cucumber+Rspec玩转BDD(3)——用户...使用Cucumber+Rspec玩转BDD(7)——测试重构