in integration test, you can test many controllers at the same time,
test a complete workflow, like login to the home page, open signup page, fill in contents, and submit......
maybe you have made sure these functions worked fine through manual test, but the integration test is to make sure it remain working fine after you or other team member make big changes!
in this chapter, we will see the real power a integration test.
1. before we used to see integration test support the contoller test style constructions such as:
get '/' response.should have_selector('title', :content => "Home")
this is not the only kind of syntax supported.
rspec integration test support a highly expressive web-navigation syntax!!
like:
visit signin_path fill_in "Name", :with => "Example User" click_button
2. test users signup failure should not make a new user.
rails g integration_test users
require 'spec_helper' describe "Users" do describe "signup" do describe "failure" do it "should not make a new user" do lambda do visit signup_path fill_in "Name", :with => "" fill_in "Email", :with => "" fill_in "Password", :with => "" fill_in "Confirmation", :with => "" click_button response.should render_template('users/new') response.should have_selector("div#error_explanation") end.should_not change(User, :count) end end end end
now it is clear what lambda is doing:
we want to make sure all the codes in the lambda block won't change the User.count.
so we put them into a lambda block then do the check on this block as a whole.
I'm still wondering where is the signup_path come from?????
it turns out that in the routes.rb
match '/signup', :to => 'users#new'
will auto define a named path
signup_path
ok, this integration test ties together all the different parts of Rails, including models, views, controllers, it provides an end to end verification that our signup machinery is working, cool, isn't it!!!
3. another integration test: users signup success should make a new user:
require 'spec_helper' describe "Users" do describe "signup" do . . . describe "success" do it "should make a new user" do lambda do visit signup_path fill_in "Name", :with => "Example User" fill_in "Email", :with => "user@example.com" fill_in "Password", :with => "foobar" fill_in "Confirmation", :with => "foobar" click_button response.should have_selector("div.flash.success", :content => "Welcome") response.should render_template('users/show') end.should change(User, :count).by(1) end end end end
BTW, when using fill_in,
you can use the label, and you can also use the css id of the element.
(the first argument is the exact text users see in browser.)
this is very useful when there is no label.
the id is resource_name with the attr.
you can find the id by view html resource.
4. ok,
git add .
git commit -m "user signup complete"
git checkout master
git merge signing-up
发表评论
-
12.3.3 scaling issue of the status feed
2011-10-30 17:54 801the problem of the implementati ... -
12.3 the status feed
2011-10-30 15:34 8501. we need to get all the micro ... -
12.2 a working follow button with Ajax
2011-10-29 18:10 9041. in the last chapter, in the ... -
12.2 a web interface for following and followers.
2011-10-28 22:14 8691.before we do the UI, we need ... -
12. following user, 12.1 relationship model
2011-10-18 14:29 7371. we need to use a relationshi ... -
11.3 manipulating microposts.
2011-10-17 15:31 8861. since all micropost actions ... -
11.2 show microposts.
2011-10-17 12:01 6941. add test to test the new use ... -
11.1 user micropost -- a micropost model.
2011-10-17 10:43 10951. we will first generate a mic ... -
10.4 destroying users.
2011-10-16 15:47 725in this chapter, we will add de ... -
10.3 showing users list
2011-10-15 20:41 762in this chapter, we will do use ... -
10.2 protect pages.
2011-10-15 15:11 645again, we will start from TD ... -
10.1 updating users.
2011-10-14 18:30 6971. git checkout -b updating-use ... -
9.4 sign out
2011-10-13 15:21 724whew!!!, last chapter is a long ... -
9.3 sign in success.
2011-10-12 15:39 7371. we will first finish the cre ... -
9.1 about flash.now[:error] vs flash[:error]
2011-10-12 15:37 714There’s a subtle difference ... -
9.2 sign in failure
2011-10-12 12:19 653start from TDD!!! 1. requir ... -
9.1 sessions
2011-10-12 10:00 640a session is a semi-permanent c ... -
what test framework should you use?
2011-10-11 16:56 0for integration test, i have no ... -
what test framework should you use?
2011-10-11 16:56 0<p>for integration test, ... -
8.3 sign up success
2011-10-11 14:39 772Chapter 8.3 this part, we will ...
相关推荐
- RSpec is a behavior-driven development (BDD) framework for Ruby that allows developers to write clear and concise tests for their applications. - It emphasizes on describing the expected behavior ...
### RSpec 入门者学习知识点详解 #### 一、RSpec 概述 RSpec 是一个流行的 Ruby 测试框架,主要用于行为驱动开发 (Behavior-Driven Development, BDD)。RSpec 的设计目的是让测试更加自然和易读,使得开发人员能够...
《RSpec Book》是一本专注于Rspec的权威指南,它详细阐述了如何使用Rspec这个强大的测试框架进行行为驱动开发(BDD)。Rspec是Ruby编程语言中的一个测试库,它使得编写可读性强、表达力丰富的测试代码成为可能。这...
RSpec is a popular tool for TDD with ruby. In this talk, we start with subject and let. Then we dive into should_receive vs. asserting side effects. Last part of this talk covers some traps and ...
《RSpec测试:行为驱动开发与RSpec、Cucumber及其他工具》 RSpec是一种用于Ruby语言的单元测试框架,它提倡一种称为“行为驱动开发”(Behavior Driven Development,BDD)的测试方式。RSpec允许开发者以自然语言的...
最后,RSpec的使用通常与持续集成(Continuous Integration)和敏捷开发实践相结合,这可以提升软件开发的效率和软件质量的可靠性。通过RSpec,团队可以更快地获得反馈,及时发现和修复问题,从而在项目中实现更快的...
RSpec是Ruby语言开发的一款行为驱动开发(BDD)工具,它通过使用领域特定语言(DSL)来帮助开发人员编写测试用例。RSpec 3.1版本是RSpec框架的更新版,提供了更多的功能和更好的用户体验。Rails是一个用Ruby语言编写的...
#### 一、RSpec框架简介与特性 **RSpec** 是 Ruby 社区中最受欢迎的行为驱动开发(Behavior Driven Development, BDD)框架之一。它为开发者提供了一种灵活的方式来定义应用程序的行为,并通过简洁易读的语法来编写...
rspec_api_documentation, 从RSpec自动生成API文档 RSpec Doc为你的Rails API生成漂亮的。查看一个示例文件。更改请查看维基以了解最新的更改。安装将rspec_api_documentation添加到你的文件gem 'rspec_a
### 使用RSpec 测试Rails 程序的知识点总结 #### 一、RSpec与Rails结合的基础概念 **RSpec**(RSpec is not a unit testing framework)是一种为Ruby编程语言设计的行为驱动开发(BDD)框架,而**Rails**是基于...
标题 "jruby-1.5.5+OperaWatir+RSpec" 暗示了这是一个关于使用 JRuby 1.5.5 版本、OperaWatir 和 RSpec 进行自动化测试的项目或者资源集合。现在,我们将深入探讨这三个关键组件以及它们在 IT 领域中的应用。 JRuby...
rspec-api-blueprint-formatter, 从RSpec测试自动生成API文档 ! RSpec APIBlueprint格式化程序从RSpec测试自动生成API文档 !像这样it 'retrievs the patients medications' do retrieve_medications
《RSpec Book》是关于行为驱动开发(BDD)的一本权威书籍,特别是针对Rspec这一Ruby语言的测试框架。本书的最新版包含了Cucumber章节,使得读者能够更好地理解和实践BDD理念。 行为驱动开发(BDD)是一种软件开发...
rspec-collection_matchers, 集合基数匹配器,从rspec期望中提取 RSpec::CollectionMatchers RSpec::CollectionMatchers 让你在一个例子中表达一个对象集合的预期结果。expect(account.shopping_cart).to have_
Sensu-RSpec集成 这是如何将RSpec测试与Sensu集成的示例。 它使用了我对贡献的check-rspec Sensu检查的略微修改。 Sensu版本是0.19.2-1 ,仪表板( 0.9.0-1 )是0.9.0-1版本。 您可以在hieradata/common.yaml更改...
### 《RSpec 书籍》:行为驱动开发与RSpec、Cucumber等工具的深入探索 #### 知识点一:RSpec 概述 - **RSpec**(RSpec)是一种为Ruby编程语言设计的行为驱动开发(Behavior Driven Development, BDD)框架。它通过...
rspec_junit_formatter, RSpec结果格式化为你的CI可以读取的JUnit RSpec JUnit格式化程序 RSpec 2 & 3结果, Jenkins可以读取。 可能还有其他的CI服务。灵感来自于的工作,在的RSpec格式化程序在对 Reporter的失望...
Ruby提供了两种强大的测试工具,RSpec和Minitest,它们通过匹配器功能可以帮助我们预防这种问题的发生。 RSpec是Ruby中广泛使用的BDD(行为驱动开发)框架,它允许开发者以自然语言的方式编写测试。匹配器是RSpec的...