SlideShare a Scribd company logo
1 of 71
Download to read offline
by Brian Sam-Bodden
@bsbodden
RSpec & Capybara
BDD & Acceptance Testing in Rails
http://www.integrallis.com
https://dl.dropboxusercontent.com/u/2968596/rspec_and_capybara.pdf
Objectives
Overview & Objectives
RSpec & Capybara
• Practical Behaviour-Driven Development
• Test-Driven Development with RSpec
• To become comfortable with the common tools used by Rubyists
• To learn and embrace the practices of successful Ruby/Rails developers
Requirements
Requirements & Objectives
What you’ll need on your system to play along...
• Git (http://git-scm.com/)
• RVM (https://rvm.io) [Optional]
• Ruby 1.9.3 (or 2.0)
• RubyGems
• Any code/text editor
Material Conventions
Part 1 - Ruby
• This 80 minute training consists of a mix of lecture time, guided exercises
and some labs (in class if we have the time, take home if we don’t)
• For the guided exercises you will see a green “follow along”
sign on the slides
• For the labs you’ll see an orange sign with the lab number
Testing
Unit, Integration, Acceptance, BDD & TDD
Testing
A Means To An End
“Our highest priority is to satisfy the customer
through early and continuous delivery
of valuable software”
http://agilemanifesto.org/principles.html
Testing
A Means To An End
• Testing traditionally done at the end of development “if time
permitted” (hello waterfall)
• No language support or frameworks (back in the old days)
• Started from the “inside” with Unit Testing Frameworks
• Lots of well tested units, we were still left with a mess at the outer layers
• BDD came in to try to reverse the testing approach
http://c2.com/cgi/wiki?TenYearsOfTestDrivenDevelopment
Testing
A Means To An End
• BDD testing frameworks are DSLs (built on top of Unit Testing
Frameworks) to “get the words rights”
• Most examples still use Units (class & methods) to teach BDD. Therefore
developers still start at the inside.
• Rails showed early own that Web Application Testing CAN be automated
• Integration testing still hard to define for most developers
• Acceptance testing is NOT integration testing (unless you mean
integrating with your users)
http://c2.com/cgi/wiki?TenYearsOfTestDrivenDevelopment
Request Handling
The Request-Response Pipeline
Model
project.rb
Controller
projects_controller.rb
View
projects/index.html.erb
Router
2 4
1
5
3
6 7
/projects
#index @projects = Project.all
@projects HTML
select * from projects...
HTML
8
1. User requests /projects
2. Rails router forwards the request to
projects_controller#index action
3. The index action creates the instance variable
@projects by using the Project model all
method
4. The all method is mapped by ActiveRecord to a
select statement for your DB
5. @projects returns back with a collection of all
Project objects
6. The index action renders the index.html.erb
view
7. An HTML table of Projects is rendered using
ERB (embedded Ruby) which has access to the
@projects variable
8. The HTML response is returned to the User
Outside-in Testing, BDD/TDD, Unit, Integration & Acceptance in one picture
BDD
Behavior-Driven Development
BDD
Behavior Driven Development
• BDD focuses TDD to deliver the maximum value possible to stakeholders
• BDD is a refinement in the language and tooling used for TDD
• As the name implies with BDD we focus on behavior specifications
• Typically BDD works from the outside in, that is starting with the parts of
the software whose behavior is directly perceive by the user
• We say BDD refines TDD in that there is an implicit decoupling of the tests
and the implementation (i.e.. don’t tests implementation specifics, test
perceived behavior)
BDD
Behavior Driven Development
• BDD focuses on “specifications” that describe the behavior of the system
• In the process of fleshing out a story the specifications start from the
outside and might move towards the inside based on need
• In the context of a Web Application this Outside-In approach typically
means that we are starting with specifications related to the User Interface
• If we are talking about a software component then we mean the API for
said component
BDD
Behavior Driven Development
• BDD helps us figure out what to test, where to start and what to ignore (or
what to make a target of opportunity)
• What to test? ➜ Use Cases or User Stories, test what something does
(behavior) rather than what something is (structure)
• Where to start? ➜ From the outer most layer
• What to ignore? ➜ Anything else... Until proven that you can’t
BDD
Behavior Driven Development
• BDD focuses on getting the words right, the resulting specifications
become an executable/self-verifying form of documentation
• BDD specifications follow a format that makes them easy to be driven by
your system’s User Stories
As a [role], I want
[goal] so that
[benefit]
Given [role and its state]
When [an event/action occurs]
Then [the benefit]
User Story Specification
TDD with RSpec
Mini-Tutorial
RSpec
Ruby’s BDD Framework
• RSpec is the most popular BDD framework for Ruby
• Created by Steven Baker in 2005, enhanced and maintained by David
Chelimsky until late 2012
• RSpec provides a DSL to write executable examples of the expected
behavior of a piece of code in a controlled context
RSpec
Ruby’s BDD Framework
• RSpec uses the method describe to create and Example Group
• Example groups can be nested using the describe or context methods
describe Bowling, "#score" do
it "returns 0 for all gutter game" do
bowling = Bowling.new
20.times { bowling.hit(0) }
expect(bowling.score).to eq(0)
end
end Example Group
Example
ExpectationMatcher
RSpec
Matchers
• RSpec comes built in with a nice collection of matchers, including:
be_true # passes if actual is truthy (not nil or false)
be_false # passes if actual is falsy (nil or false)
be_nil # passes if actual is nil
be # passes if actual is truthy (not nil or false)
expect { ... }.to raise_error
expect { ... }.to raise_error(ErrorClass)
expect { ... }.to raise_error("message")
expect { ... }.to raise_error(ErrorClass, "message")
expect { ... }.to throw_symbol
expect { ... }.to throw_symbol(:symbol)
expect { ... }.to throw_symbol(:symbol, 'value')
be_xxx # passes if actual.xxx?
have_xxx(:arg) # passes if actual.has_xxx?(:arg)
RSpec
Matchers
• and ...
https://www.relishapp.com/rspec/rspec-expectations/v/2-13/docs/built-in-matchers
be_empty
be(expected) # passes if actual.equal?(expected)
eq(expected) # passes if actual == expected
== expected # passes if actual == expected
eql(expected) # passes if actual.eql?(expected)
equal(expected) # passes if actual.equal?(expected)
be > expected
be >= expected
be <= expected
be < expected
=~ /expression/
match(/expression/)
be_within(delta).of(expected)
be_instance_of(expected)
be_kind_of(expected)
Test-Driven Development
Drive your Development with Tests
• TDD is not *really* about testing
• TDD is a design technique
• TDD leads to cleaner code with separation of concerns
• Cleaner code is more reliable and easier to maintain (Duh)
Test-Driven Development
Drive your Development with Tests
• TDD creates a tight loop of development that cognitively engages us
• TDD gives us lightweight rigor by making development, goal-oriented
with a clear goal setting, goal reaching and improvement stages
• The stages of TDD are commonly known as the Red-Green-Refactor loop
Test-Driven Development
Drive your Development with Tests
• The Red-Green-Refactor Loop:
Write a failing test for new functionality
RED
GREENREFACTOR
Write the minimal code to pass the testClean up & improve without adding functionality
Test-Driven Development
Evolve your Code with Tests
• Let’s work through a simple TDD/BDD exercise using RSpec
• We’ll design a simple shopping cart class
• We’ll start by creating a new folder for our exercise and adding a .rvmrc file
and a Gemfile
/>mkdir rspec-follow-along
/>cd rspec-follow-along
/>echo 'rvm use 1.9.3@rspec-follow-along' > .rvmrc
/>touch Gemfile
/>mkdir spec
/>mkdir lib
source 'https://rubygems.org'
group :test do
gem 'rspec'
end
Test-Driven Development
Evolve your Code with Tests
• With our project configure for RVM and a Gemfile in place we can reenter
the directory to activate the Gemset and run the bundle command:
/>cd ..
/>cd rspec-follow-along/
Using /Users/user/.rvm/gems/ruby-1.9.3-p374 with gemset rspec-follow-along
bsb in ~/Courses/code/rspec-follow-along using ruby-1.9.3-p374@rspec-follow-along
/> bundle
Using diff-lcs (1.1.3)
Using rspec-core (2.12.2)
Using rspec-expectations (2.12.1)
Using rspec-mocks (2.12.2)
Using rspec (2.12.0)
Using bundler (1.2.3)
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
describe Cart do
end
Test-Driven Development
Evolve your Code with Tests
• We’ll start the RGR loop with the simplest possible failure:
”There is no Cart!”
• Create the file cart_spec.rb in the spec directory with the following contents:
Test-Driven Development
Evolve your Code with Tests
• Let’s run the specs using the rspec command and passing the spec
directory as an argument
• Have we arrived at the RED state in our red-green-refactor cycle?
/>rspec spec
/Users/bsb/Courses/code/rspec-follow-along/spec/cart_spec.rb:1:in `<top (required)>':
uninitialized constant Cart (NameError)
Hint: if you have a failure with no tests it typically means
that you need a test (but let’s ignore that for a second...)
class Cart
end
Test-Driven Development
Evolve your Code with Tests
• Let’s create the Cart class in a /lib folder and require it in our spec:
/> rspec spec
No examples found.
Finished in 0.00006 seconds
0 examples, 0 failures
require_relative '../lib/cart.rb'
describe Cart do
end
• Now we have no failures but also we have no specs...
Test-Driven Development
Evolve your Code with Tests
• Let’s craft our first real test to drive the development of the Cart
• The spec to tackle is: “An instance of Cart when new contains no items”
require_relative '../lib/cart.rb'
describe Cart do
context "a new cart" do
it "contains no items" do
expect(@cart).to be_empty
end
end
end
Test-Driven Development
Evolve your Code with Tests
• If we run the specs we can see a failure:
/> rspec spec
F
Failures:
1) Cart a new cart contains no items
Failure/Error: expect(@cart).to be_empty
NoMethodError:
undefined method `empty?' for nil:NilClass
# ./spec/cart_spec.rb:6:in `block (3 levels) in <top (required)>
Finished in 0.00243 seconds
1 example, 1 failure
Now we have our first “real” test-driven failure
(and that is a good thing!)
Test-Driven Development
Evolve your Code with Tests
• One of the mantras of BDD is to “get the words right”
• If you noticed on the last run the spec output read as “Cart a new cart
contains no items”
• RSpec is flexible enough to allow us to pass a string to be prefixed to the
describe block to make tailor the output to our needs
require_relative '../lib/cart.rb'
describe "An instance of", Cart do
context "when new" do
it "contains no items" do
expect(@cart).to be_empty
end
end
end
Test-Driven Development
Evolve your Code with Tests
• If we run the specs we can see that the output now matches the desire
spec wording
/> rspec spec
F
Failures:
1) An instance of Cart when new contains no items
Failure/Error: expect(@cart).to be_empty
NoMethodError:
undefined method `empty?' for nil:NilClass
# ./spec/cart_spec.rb:6:in `block (3 levels) in <top (required)>'
Finished in 0.00154 seconds
1 example, 1 failure
Failed examples:
rspec ./spec/cart_spec.rb:5 # An instance of Cart when new contains no items
Test-Driven Development
Evolve your Code with Tests
• The output shows that we have two failures, one implicit and one explicit
• Explicit Failure: We are assuming that a cart has an #empty? method
• Implicit Failure: The instance variable @cart has not been initialized
Failures:
1) An instance of Cart when new contains no items
Failure/Error: expect(@cart).to be_empty
NoMethodError:
undefined method `empty?' for nil:NilClass
# ./spec/cart_spec.rb:6:in `block (3 levels) in <top (required)>'
Test-Driven Development
Evolve your Code with Tests
• We’ll start by addressing the fact that our test fixture hasn’t been setup
• Just adding the line @cart = Cart.new wouldn’t be very TDDish
• What we should do is first make the failure explicit by writing a test for it!
require_relative '../lib/cart.rb'
describe "An instance of", Cart do
it "should be properly initialized" do
expect(@cart).to be_a(Cart)
end
...
Remember our initial failure with no tests?
Test-Driven Development
Evolve your Code with Tests
• Now we have two valid failing tests to pass, let’s get on with it!
...
1) An instance of Cart should be properly initialized
Failure/Error: expect(@cart).to be_a(Cart)
expected nil to be a kind of Cart
# ./spec/cart_spec.rb:6:in `block (2 levels) in <top (required)>'
2) An instance of Cart when new contains no items
Failure/Error: expect(@cart).to be_empty
NoMethodError:
undefined method `empty?' for nil:NilClass
# ./spec/cart_spec.rb:11:in `block (3 levels) in <top (required)>'
Finished in 0.00233 seconds
2 examples, 2 failures
Test-Driven Development
Evolve your Code with Tests
• We’ll pass the test by adding the line @cart = Cart.new in a before-each
block:
describe "An instance of", Cart do
before :each do
@cart = Cart.new
end
...
1) An instance of Cart when new contains no items
Failure/Error: expect(@cart).to be_empty
NoMethodError:
undefined method `empty?' for #<Cart:0x007fc98316cb60>
...
Test-Driven Development
Evolve your Code with Tests
• Let’s add a skeleton empty? method to the Cart class:
class Cart
def empty?
nil
end
end
...
1) An instance of Cart when new contains no items
Failure/Error: expect(@cart).to be_empty
expected empty? to return true, got nil
# ./spec/cart_spec.rb:15:in `block (3 levels) in <top (required)>'
...
Test-Driven Development
Evolve your Code with Tests
• Now we can comply with the spec by providing an implementation of our
Cart
• In this case we are using a Hash to hold our items and delegating to the
@items#empty? method
class Cart
def initialize
@items = {}
end
def empty?
@items.empty?
end
end
/> rspec spec
..
Finished in 0.00196 seconds
2 examples, 0 failures
We’ve reached the GREEN state
Test-Driven Development
Drive your Development with Tests
• In the REFACTOR state we concentrate on making the current
implementation better, cleaner and more robust
• It is very likely that early on in the development there won’t be much to
refactor
• The need for refactoring is a side-effect of increasing complexity and
interaction between classes and subsystems
• Refactoring can also introduce implementation specific specs or reveal
holes in your previous specs
Test-Driven Development
Evolve your Code with Tests
• Let’s use Ruby’s Forwardable module to simplify the delegation of the
collection methods to the @items Hash:
class Cart
extend Forwardable
def_delegator :@items, :empty?
def initialize
@items = {}
end
end
/>rspec spec
..
Finished in 0.00365 seconds
2 examples, 0 failures
Test-Driven Development
RSpec Command
• The RSpec command provides several arguments to tailor the run and output
of your specifications
• For example to see the group and example names in the output use
--format documentation
/> rspec --format documentation
An instance of Cart
should be properly initialized
when new
contains no items
Finished in 0.00224 seconds
2 examples, 0 failures
Lab 1.0
TDD & BDD
• Lab 1.0 consists of 4 specs to be implemented in a TDD fashion:
• “An new and empty cart total value should be $0.0”
• “An empty cart should no longer be empty after adding an item”
• “A cart with items should have a total value equal to the sum of each items’
value times its quantity”
• “Increasing the quantity of an item should not increase the Carts’ unique
items count”
BDD with Capybara
Mini-Tutorial
Acceptance
Acceptance Testing
• Proper acceptance tests treat your application as a black box
• They should know as little as possible about what happens under the hood
• They’re just there to interact with the interface and observe the results
• Jeff Casimir says...
“A great testing strategy is to extensively cover the data layer with unit tests
then skip all the way up to acceptance tests. This approach gives great code
coverage and builds a test suite that can flex with a changing codebase.”
Capybara
Acceptance test framework for web applications
• Capybara is a lightweight alternative to Cucumber
• Capybara is a browser automation library
• Helps you test web applications by simulating how a real user would
interact with your app
• It is agnostic about the driver running your tests and comes with
Rack::Test and Selenium support built in
• WebKit is supported through an external gem
RSpec, Capybara, and Steak
Acceptance test framework for web applications
• Many developers don’t want to bother with Cucumber
• They want outside-in testing without the translation step
• The Steak project integrated RSpec and Capybara directly
• Now we can write acceptance tests just like you write unit tests, greatly
simplifying the process
• In late 2010 the Capybara absorbed the Steak syntax
Rack::Test
Acceptance test framework for web applications
• Capybara uses Rack::Test by default
• Rack::Test interacts with your app at the Rack level
• It runs requests against your app, then provides the resulting HTML to
Capybara and RSpec for examination.
• Rack::Test is completely headless (and therefore fast)
• The disadvantage is that it doesn’t process JavaScript (or give you visual
feedback)
• To test JavaScript in your acceptance tests you can use the
selenium-webdriver or capybara-webkit driver.
Capybara DSL
How to Drive the Browser
• The folks at ThoughtBot
put a nice Capybara Cheat
Sheet
https://learn.thoughtbot.com/test-driven-rails-resources/capybara.pdf
Capybara DSL
How to Drive the Browser
https://learn.thoughtbot.com/test-driven-rails-resources/capybara.pdf
Capybara DSL
How to Drive the Browser
https://learn.thoughtbot.com/test-driven-rails-resources/capybara.pdf
Acceptance Testing w/ Capybara
Testing a Rails Application
• We are going to mimic a user’s interaction with a very simple Rails app
• The bulk of the functionality in the app will be provided by the devise
(authentication) library and the high_voltage (static pages) gems
• To concentrate on the subtleties of Capybara we will test an existing
application
• Let start by using git to clone the master branch of the repository at
https://github.com/integrallis/learn-rspec-capybara
/>git clone git://github.com/integrallis/learn-rspec-capybara.git
Acceptance Testing w/ Capybara
Testing a Rails Application
• CD in and out of the application to activate the RVM Gemset
• Bundle the application (bundle install), migrate it (rake db:migrate),
prepare the test database (rake db:test:prepare) and launch it (rails s)
/>rails s
=> Booting WEBrick
=> Rails 3.2.13 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2013-04-29 10:21:05] INFO WEBrick 1.3.1
[2013-04-29 10:21:05] INFO ruby 1.9.3 (2013-02-22) [x86_64-darwin12.2.1]
[2013-04-29 10:21:05] INFO WEBrick::HTTPServer#start: pid=87936 port=3000
Acceptance Testing w/ Capybara
Testing a Rails Application
• Let’s examine the application by opening the URL http://localhost:3000 on a
capable browser
• All pages are locked until we register on the Sign Up Page (provided by devise):
Sign Up Page - /users/sign_up
Acceptance Testing w/ Capybara
Testing a Rails Application
• Once you are signed up you are redirected to the home page and shown a
flash message:
Home Page - /
Acceptance Testing w/ Capybara
Testing a Rails Application
• About and home pages are ERB templates served by high_voltage:
About Page - /about
Acceptance Testing w/ Capybara
Testing a Rails Application
• The user profile page (provided by devise):
User Profile Page - /users/edit
Acceptance Testing w/ Capybara
Testing a Rails Application
• The Sign In Page (also provided by devise):
Sign In Page - /users/sign_in
Acceptance Testing w/ Capybara
Testing a Rails Application
• If we run the specs using rspec you’ll see two passing specs and the rest
as pending:
/>rspec
User
should require email to be set
should require case sensitive unique value for email
Flash Notices
can be dismissed by the user (PENDING: No reason given)
User Registration
failure
displays an error message (PENDING: No reason given)
shows the correct navigation links (PENDING: No reason given)
success
displays a welcome message (PENDING: No reason given)
Acceptance Testing w/ Capybara
Testing a Rails Application
• Let’s examine the two passing specs:
require 'spec_helper'
describe User do
it { should validate_presence_of(:email) }
it { should validate_uniqueness_of(:email) }
end
• They’re just simple validation messages via shoulda-matchers
Acceptance Testing w/ Capybara
Testing a Rails Application
• Let’s start by tacking the Sessions Spec, specifically a successful login:
context "success" do
before do
# sign in
end
it "displays a welcome message" do
pending
end
it "shows the correct navigation links" do
# should not see 'Sign in' and 'Sign up'
# should see 'Profile' or 'Sign out'
pending
end
end
/spec/features/sessions_spec.rb
Acceptance Testing w/ Capybara
Testing a Rails Application
• In the before block we’ll fill in the email and passwords field and click the
sign in button:
context "success" do
before do
fill_in 'Email', with: email
fill_in 'Password', with: password
click_button 'Sign in'
end
...
end
/spec/features/sessions_spec.rb
Change and Run your specs!
Acceptance Testing w/ Capybara
Testing a Rails Application
• Capybara provides us with the “page” object which we can inspect, for
example, with the have_content method:
it "displays a welcome message" do
expect(page).to have_content('Signed in successfully.')
end
/spec/features/sessions_spec.rb
Change and Run your specs!
Acceptance Testing w/ Capybara
Testing a Rails Application
• We can also check for certain links to be or not be present in the page:
it "shows the correct navigation links" do
within('.navbar') do
expect(page).to have_link('Profile')
expect(page).to have_link('Sign out')
expect(page).to_not have_link('Sign in')
expect(page).to_not have_link('Sign up')
end
end
/spec/features/sessions_spec.rb
Change and Run your specs!
Acceptance Testing w/ Capybara
Testing a Rails Application
• Next let’s tackle the flash notices spec. Notice that in the before block we
use the visit method with a Rails named route:
require 'spec_helper'
describe "Flash Notices", js: true do
before do
# When an unauthenticated user visit the edit_user_registration_path they
# are redirected with a flash notice
visit edit_user_registration_path
end
it "can be dismissed by the user" do
# check that the flash message exists click to close the flash message
# check that the flash message is gone
pending
end
end
/spec/features/flash_notices.rb
Acceptance Testing w/ Capybara
Testing a Rails Application
• First, we’ll check that the text of the flash message has appeared on the
page:
it "can be dismissed by the user" do
expect(page).to have_content("You need to sign in or sign up before continuing.")
end
/spec/features/flash_notices.rb
Acceptance Testing w/ Capybara
Testing a Rails Application
• Next will, find the alert div using the class CSS selector
• Inside of the alert div will find the close HREF and click it
it "can be dismissed by the user" do
expect(page).to have_content("You need to sign in or sign up before continuing.")
within('.alert') do
find('.close').click
end
end
/spec/features/flash_notices.rb
Acceptance Testing w/ Capybara
Testing a Rails Application
• Now, we check that the content of the flash alert is no longer on the page:
it "can be dismissed by the user" do
expect(page).to have_content("You need to sign in or sign up before continuing.")
within('.alert') do
find('.close').click
end
expect(page).to_not have_content("You need to sign in or sign up before continuing.")
end
/spec/features/flash_notices.rb
Lab 2.0
Capybara
• In Lab 2.0, complete the remaining acceptance specs:
• The Registrations Spec in /spec/features/registrations_spec.rb
• The Cancel Registration Spec in /spec/features/cancel_registration.rb
Conclusions & Objectives
Practice, Practice, Practice
• Don’t take TDD & BDD as dogma. Find ways to make it work for you!
• I don’t always use TDD & BDD but when I do ...
• If you can TDD/BDD keep the code local until you can check it in with a
corresponding test
Thanks
http://integrallis.com

More Related Content

What's hot

APIs: A Better Alternative to Page Objects
APIs: A Better Alternative to Page ObjectsAPIs: A Better Alternative to Page Objects
APIs: A Better Alternative to Page ObjectsSauce Labs
 
Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando...
Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando...Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando...
Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando...Applitools
 
Introduction to Bdd and cucumber
Introduction to Bdd and cucumberIntroduction to Bdd and cucumber
Introduction to Bdd and cucumberNibu Baby
 
Automated Testing in Angular Slides
Automated Testing in Angular SlidesAutomated Testing in Angular Slides
Automated Testing in Angular SlidesJim Lynch
 
Testing Code.org's Interactive CS Curriculum
Testing Code.org's Interactive CS CurriculumTesting Code.org's Interactive CS Curriculum
Testing Code.org's Interactive CS CurriculumBrian Jordan
 
Better Page Object Handling with Loadable Component Pattern
Better Page Object Handling with Loadable Component PatternBetter Page Object Handling with Loadable Component Pattern
Better Page Object Handling with Loadable Component PatternSargis Sargsyan
 
Bdd – with cucumber and gherkin
Bdd – with cucumber and gherkinBdd – with cucumber and gherkin
Bdd – with cucumber and gherkinArati Joshi
 
Behavior Driven Development (BDD) and Agile Testing
Behavior Driven Development (BDD) and Agile TestingBehavior Driven Development (BDD) and Agile Testing
Behavior Driven Development (BDD) and Agile Testingdversaci
 
API Test Automation Using Karate (Anil Kumar Moka)
API Test Automation Using Karate (Anil Kumar Moka)API Test Automation Using Karate (Anil Kumar Moka)
API Test Automation Using Karate (Anil Kumar Moka)Peter Thomas
 
Better End-to-End Testing with Page Objects Model using Protractor
Better End-to-End Testing with Page Objects Model using ProtractorBetter End-to-End Testing with Page Objects Model using Protractor
Better End-to-End Testing with Page Objects Model using ProtractorKasun Kodagoda
 
BDD with JBehave and Selenium
BDD with JBehave and SeleniumBDD with JBehave and Selenium
BDD with JBehave and SeleniumNikolay Vasilev
 
BDD testing with cucumber
BDD testing with cucumberBDD testing with cucumber
BDD testing with cucumberDaniel Kummer
 
Behavior Driven Development and Automation Testing Using Cucumber
Behavior Driven Development and Automation Testing Using CucumberBehavior Driven Development and Automation Testing Using Cucumber
Behavior Driven Development and Automation Testing Using CucumberKMS Technology
 
Protractor for angularJS
Protractor for angularJSProtractor for angularJS
Protractor for angularJSKrishna Kumar
 
AngularJS and Protractor
AngularJS and ProtractorAngularJS and Protractor
AngularJS and ProtractorFilipe Falcão
 
Jest: Frontend Testing richtig gemacht @WebworkerNRW
Jest: Frontend Testing richtig gemacht @WebworkerNRWJest: Frontend Testing richtig gemacht @WebworkerNRW
Jest: Frontend Testing richtig gemacht @WebworkerNRWHolger Grosse-Plankermann
 
CI / CD w/ Codeception
CI / CD w/ CodeceptionCI / CD w/ Codeception
CI / CD w/ CodeceptionTudor Barbu
 

What's hot (20)

APIs: A Better Alternative to Page Objects
APIs: A Better Alternative to Page ObjectsAPIs: A Better Alternative to Page Objects
APIs: A Better Alternative to Page Objects
 
Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando...
Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando...Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando...
Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando...
 
Introduction to Bdd and cucumber
Introduction to Bdd and cucumberIntroduction to Bdd and cucumber
Introduction to Bdd and cucumber
 
Automated Testing in Angular Slides
Automated Testing in Angular SlidesAutomated Testing in Angular Slides
Automated Testing in Angular Slides
 
Testing Code.org's Interactive CS Curriculum
Testing Code.org's Interactive CS CurriculumTesting Code.org's Interactive CS Curriculum
Testing Code.org's Interactive CS Curriculum
 
Test Automation Framework with BDD and Cucumber
Test Automation Framework with BDD and CucumberTest Automation Framework with BDD and Cucumber
Test Automation Framework with BDD and Cucumber
 
Better Page Object Handling with Loadable Component Pattern
Better Page Object Handling with Loadable Component PatternBetter Page Object Handling with Loadable Component Pattern
Better Page Object Handling with Loadable Component Pattern
 
Bdd – with cucumber and gherkin
Bdd – with cucumber and gherkinBdd – with cucumber and gherkin
Bdd – with cucumber and gherkin
 
Behavior Driven Development (BDD) and Agile Testing
Behavior Driven Development (BDD) and Agile TestingBehavior Driven Development (BDD) and Agile Testing
Behavior Driven Development (BDD) and Agile Testing
 
API Test Automation Using Karate (Anil Kumar Moka)
API Test Automation Using Karate (Anil Kumar Moka)API Test Automation Using Karate (Anil Kumar Moka)
API Test Automation Using Karate (Anil Kumar Moka)
 
Better End-to-End Testing with Page Objects Model using Protractor
Better End-to-End Testing with Page Objects Model using ProtractorBetter End-to-End Testing with Page Objects Model using Protractor
Better End-to-End Testing with Page Objects Model using Protractor
 
BDD with JBehave and Selenium
BDD with JBehave and SeleniumBDD with JBehave and Selenium
BDD with JBehave and Selenium
 
BDD testing with cucumber
BDD testing with cucumberBDD testing with cucumber
BDD testing with cucumber
 
Behavior Driven Development and Automation Testing Using Cucumber
Behavior Driven Development and Automation Testing Using CucumberBehavior Driven Development and Automation Testing Using Cucumber
Behavior Driven Development and Automation Testing Using Cucumber
 
Protractor for angularJS
Protractor for angularJSProtractor for angularJS
Protractor for angularJS
 
AngularJS and Protractor
AngularJS and ProtractorAngularJS and Protractor
AngularJS and Protractor
 
Jest: Frontend Testing richtig gemacht @WebworkerNRW
Jest: Frontend Testing richtig gemacht @WebworkerNRWJest: Frontend Testing richtig gemacht @WebworkerNRW
Jest: Frontend Testing richtig gemacht @WebworkerNRW
 
BDD for APIs
BDD for APIsBDD for APIs
BDD for APIs
 
Paper CS
Paper CSPaper CS
Paper CS
 
CI / CD w/ Codeception
CI / CD w/ CodeceptionCI / CD w/ Codeception
CI / CD w/ Codeception
 

Viewers also liked

Testing Microservices with a Citrus twist
Testing Microservices with a Citrus twistTesting Microservices with a Citrus twist
Testing Microservices with a Citrus twistchristophd
 
Testing Java EE apps with Arquillian
Testing Java EE apps with ArquillianTesting Java EE apps with Arquillian
Testing Java EE apps with ArquillianIvan Ivanov
 
Bdd (Behavior Driven Development)
Bdd (Behavior Driven Development)Bdd (Behavior Driven Development)
Bdd (Behavior Driven Development)Helder De Oliveira
 
Arquillian & Citrus
Arquillian & CitrusArquillian & Citrus
Arquillian & Citruschristophd
 
Lunch and learn: Cucumber and Capybara
Lunch and learn: Cucumber and CapybaraLunch and learn: Cucumber and Capybara
Lunch and learn: Cucumber and CapybaraMarc Seeger
 
Pruebas funcionales de Software
Pruebas funcionales de SoftwarePruebas funcionales de Software
Pruebas funcionales de SoftwareBrian Pando
 
Three Uses Of JIRA Beyond Bug Tracking
Three Uses Of JIRA Beyond Bug TrackingThree Uses Of JIRA Beyond Bug Tracking
Three Uses Of JIRA Beyond Bug TrackingAtlassian
 
TestLink introduction
TestLink introductionTestLink introduction
TestLink introductionDavid Ionut
 
Introduction To Confluence
Introduction To ConfluenceIntroduction To Confluence
Introduction To ConfluenceHua Soon Sim
 
Jira as a Tool for Test Management
Jira as a Tool for Test ManagementJira as a Tool for Test Management
Jira as a Tool for Test ManagementMaija Laksa
 
Using JIRA Software for Issue Tracking
Using JIRA Software for Issue TrackingUsing JIRA Software for Issue Tracking
Using JIRA Software for Issue TrackingAnjali Rao
 
Introduction To Jira
Introduction To JiraIntroduction To Jira
Introduction To JiraHua Soon Sim
 
Capybara with Rspec
Capybara with RspecCapybara with Rspec
Capybara with RspecOmnia Helmi
 
Gerrit is Getting Native with RPM, Deb and Docker
Gerrit is Getting Native with RPM, Deb and DockerGerrit is Getting Native with RPM, Deb and Docker
Gerrit is Getting Native with RPM, Deb and DockerLuca Milanesio
 
Continuous integration using Jenkins and Sonar
Continuous integration using Jenkins and SonarContinuous integration using Jenkins and Sonar
Continuous integration using Jenkins and SonarPascal Larocque
 
Sonar qube to impove code quality
Sonar qube   to impove code qualitySonar qube   to impove code quality
Sonar qube to impove code qualityMani Sarkar
 
Design First API's with RAML and SoapUI
Design First API's with RAML and SoapUIDesign First API's with RAML and SoapUI
Design First API's with RAML and SoapUIDaniel Feist
 

Viewers also liked (20)

Testing Microservices with a Citrus twist
Testing Microservices with a Citrus twistTesting Microservices with a Citrus twist
Testing Microservices with a Citrus twist
 
Testing Java EE apps with Arquillian
Testing Java EE apps with ArquillianTesting Java EE apps with Arquillian
Testing Java EE apps with Arquillian
 
Bdd (Behavior Driven Development)
Bdd (Behavior Driven Development)Bdd (Behavior Driven Development)
Bdd (Behavior Driven Development)
 
Arquillian & Citrus
Arquillian & CitrusArquillian & Citrus
Arquillian & Citrus
 
Workshop calabash appium
Workshop calabash appiumWorkshop calabash appium
Workshop calabash appium
 
Lunch and learn: Cucumber and Capybara
Lunch and learn: Cucumber and CapybaraLunch and learn: Cucumber and Capybara
Lunch and learn: Cucumber and Capybara
 
Pruebas funcionales de Software
Pruebas funcionales de SoftwarePruebas funcionales de Software
Pruebas funcionales de Software
 
Three Uses Of JIRA Beyond Bug Tracking
Three Uses Of JIRA Beyond Bug TrackingThree Uses Of JIRA Beyond Bug Tracking
Three Uses Of JIRA Beyond Bug Tracking
 
TestLink introduction
TestLink introductionTestLink introduction
TestLink introduction
 
Introduction To Confluence
Introduction To ConfluenceIntroduction To Confluence
Introduction To Confluence
 
Jira as a Tool for Test Management
Jira as a Tool for Test ManagementJira as a Tool for Test Management
Jira as a Tool for Test Management
 
Using JIRA Software for Issue Tracking
Using JIRA Software for Issue TrackingUsing JIRA Software for Issue Tracking
Using JIRA Software for Issue Tracking
 
Introduction To Jira
Introduction To JiraIntroduction To Jira
Introduction To Jira
 
Capybara with Rspec
Capybara with RspecCapybara with Rspec
Capybara with Rspec
 
Next level of Appium
Next level of AppiumNext level of Appium
Next level of Appium
 
Automate you Appium test like a pro!
Automate you Appium test like a pro!Automate you Appium test like a pro!
Automate you Appium test like a pro!
 
Gerrit is Getting Native with RPM, Deb and Docker
Gerrit is Getting Native with RPM, Deb and DockerGerrit is Getting Native with RPM, Deb and Docker
Gerrit is Getting Native with RPM, Deb and Docker
 
Continuous integration using Jenkins and Sonar
Continuous integration using Jenkins and SonarContinuous integration using Jenkins and Sonar
Continuous integration using Jenkins and Sonar
 
Sonar qube to impove code quality
Sonar qube   to impove code qualitySonar qube   to impove code quality
Sonar qube to impove code quality
 
Design First API's with RAML and SoapUI
Design First API's with RAML and SoapUIDesign First API's with RAML and SoapUI
Design First API's with RAML and SoapUI
 

Similar to Rspec and Capybara Intro Tutorial at RailsConf 2013

Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & Cucumber
       Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & Cucumber       Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & Cucumber
Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & CucumberUdaya Kiran
 
The details of CI/CD environment for Ruby
The details of CI/CD environment for RubyThe details of CI/CD environment for Ruby
The details of CI/CD environment for RubyHiroshi SHIBATA
 
2011-02-03 LA RubyConf Rails3 TDD Workshop
2011-02-03 LA RubyConf Rails3 TDD Workshop2011-02-03 LA RubyConf Rails3 TDD Workshop
2011-02-03 LA RubyConf Rails3 TDD WorkshopWolfram Arnold
 
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...Nilesh Panchal
 
Exploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQLExploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQLBarry Jones
 
Ruby On Rails Tutorial
Ruby On Rails TutorialRuby On Rails Tutorial
Ruby On Rails Tutorialsunniboy
 
Solid And Sustainable Development in Scala
Solid And Sustainable Development in ScalaSolid And Sustainable Development in Scala
Solid And Sustainable Development in ScalaKazuhiro Sera
 
Everything-as-code – Polyglotte Entwicklung in der Praxis
Everything-as-code – Polyglotte Entwicklung in der PraxisEverything-as-code – Polyglotte Entwicklung in der Praxis
Everything-as-code – Polyglotte Entwicklung in der PraxisQAware GmbH
 
The "Holy Grail" of Dev/Ops
The "Holy Grail" of Dev/OpsThe "Holy Grail" of Dev/Ops
The "Holy Grail" of Dev/OpsErik Osterman
 
Quick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmineQuick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmineGil Fink
 
End-to-end web-testing in ruby ecosystem
End-to-end web-testing in ruby ecosystemEnd-to-end web-testing in ruby ecosystem
End-to-end web-testing in ruby ecosystemAlex Mikitenko
 
2014 11 20 Drupal 7 -> 8 test migratie
2014 11 20 Drupal 7 -> 8 test migratie2014 11 20 Drupal 7 -> 8 test migratie
2014 11 20 Drupal 7 -> 8 test migratiehcderaad
 
Rspec presentation
Rspec presentationRspec presentation
Rspec presentationMyo T Kyaw
 
Solid and Sustainable Development in Scala
Solid and Sustainable Development in ScalaSolid and Sustainable Development in Scala
Solid and Sustainable Development in Scalascalaconfjp
 
Functional Scala 2022 - scalajs Alexis.pdf
Functional Scala 2022 - scalajs Alexis.pdfFunctional Scala 2022 - scalajs Alexis.pdf
Functional Scala 2022 - scalajs Alexis.pdfssusercd195b
 
RoR (Ruby on Rails)
RoR (Ruby on Rails)RoR (Ruby on Rails)
RoR (Ruby on Rails)scandiweb
 

Similar to Rspec and Capybara Intro Tutorial at RailsConf 2013 (20)

Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & Cucumber
       Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & Cucumber       Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & Cucumber
Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & Cucumber
 
The details of CI/CD environment for Ruby
The details of CI/CD environment for RubyThe details of CI/CD environment for Ruby
The details of CI/CD environment for Ruby
 
2011-02-03 LA RubyConf Rails3 TDD Workshop
2011-02-03 LA RubyConf Rails3 TDD Workshop2011-02-03 LA RubyConf Rails3 TDD Workshop
2011-02-03 LA RubyConf Rails3 TDD Workshop
 
Tdd
TddTdd
Tdd
 
Supa fast Ruby + Rails
Supa fast Ruby + RailsSupa fast Ruby + Rails
Supa fast Ruby + Rails
 
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
 
Exploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQLExploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQL
 
Basic RSpec 2
Basic RSpec 2Basic RSpec 2
Basic RSpec 2
 
Ruby On Rails Tutorial
Ruby On Rails TutorialRuby On Rails Tutorial
Ruby On Rails Tutorial
 
Solid And Sustainable Development in Scala
Solid And Sustainable Development in ScalaSolid And Sustainable Development in Scala
Solid And Sustainable Development in Scala
 
Everything-as-code – Polyglotte Entwicklung in der Praxis
Everything-as-code – Polyglotte Entwicklung in der PraxisEverything-as-code – Polyglotte Entwicklung in der Praxis
Everything-as-code – Polyglotte Entwicklung in der Praxis
 
The "Holy Grail" of Dev/Ops
The "Holy Grail" of Dev/OpsThe "Holy Grail" of Dev/Ops
The "Holy Grail" of Dev/Ops
 
Quick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmineQuick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmine
 
End-to-end web-testing in ruby ecosystem
End-to-end web-testing in ruby ecosystemEnd-to-end web-testing in ruby ecosystem
End-to-end web-testing in ruby ecosystem
 
2014 11 20 Drupal 7 -> 8 test migratie
2014 11 20 Drupal 7 -> 8 test migratie2014 11 20 Drupal 7 -> 8 test migratie
2014 11 20 Drupal 7 -> 8 test migratie
 
Rspec presentation
Rspec presentationRspec presentation
Rspec presentation
 
Solid and Sustainable Development in Scala
Solid and Sustainable Development in ScalaSolid and Sustainable Development in Scala
Solid and Sustainable Development in Scala
 
Functional Scala 2022 - scalajs Alexis.pdf
Functional Scala 2022 - scalajs Alexis.pdfFunctional Scala 2022 - scalajs Alexis.pdf
Functional Scala 2022 - scalajs Alexis.pdf
 
Rspec
RspecRspec
Rspec
 
RoR (Ruby on Rails)
RoR (Ruby on Rails)RoR (Ruby on Rails)
RoR (Ruby on Rails)
 

More from Brian Sam-Bodden

Baruco 2014 - Rubymotion Workshop
Baruco 2014 - Rubymotion WorkshopBaruco 2014 - Rubymotion Workshop
Baruco 2014 - Rubymotion WorkshopBrian Sam-Bodden
 
Server-Side Push: Comet, Web Sockets come of age (OSCON 2013)
Server-Side Push: Comet, Web Sockets come of age (OSCON 2013)Server-Side Push: Comet, Web Sockets come of age (OSCON 2013)
Server-Side Push: Comet, Web Sockets come of age (OSCON 2013)Brian Sam-Bodden
 
Ruby Metaprogramming - OSCON 2008
Ruby Metaprogramming - OSCON 2008Ruby Metaprogramming - OSCON 2008
Ruby Metaprogramming - OSCON 2008Brian Sam-Bodden
 
RailsConf 2013: RubyMotion
RailsConf 2013: RubyMotionRailsConf 2013: RubyMotion
RailsConf 2013: RubyMotionBrian Sam-Bodden
 
Road to mobile w/ Sinatra, jQuery Mobile, Spine.js and Mustache
Road to mobile w/ Sinatra, jQuery Mobile, Spine.js and MustacheRoad to mobile w/ Sinatra, jQuery Mobile, Spine.js and Mustache
Road to mobile w/ Sinatra, jQuery Mobile, Spine.js and MustacheBrian Sam-Bodden
 
Trellis Framework At RubyWebConf
Trellis Framework At RubyWebConfTrellis Framework At RubyWebConf
Trellis Framework At RubyWebConfBrian Sam-Bodden
 
Bitter Java, Sweeten with JRuby
Bitter Java, Sweeten with JRubyBitter Java, Sweeten with JRuby
Bitter Java, Sweeten with JRubyBrian Sam-Bodden
 

More from Brian Sam-Bodden (10)

Baruco 2014 - Rubymotion Workshop
Baruco 2014 - Rubymotion WorkshopBaruco 2014 - Rubymotion Workshop
Baruco 2014 - Rubymotion Workshop
 
Server-Side Push: Comet, Web Sockets come of age (OSCON 2013)
Server-Side Push: Comet, Web Sockets come of age (OSCON 2013)Server-Side Push: Comet, Web Sockets come of age (OSCON 2013)
Server-Side Push: Comet, Web Sockets come of age (OSCON 2013)
 
Ruby Metaprogramming - OSCON 2008
Ruby Metaprogramming - OSCON 2008Ruby Metaprogramming - OSCON 2008
Ruby Metaprogramming - OSCON 2008
 
RailsConf 2013: RubyMotion
RailsConf 2013: RubyMotionRailsConf 2013: RubyMotion
RailsConf 2013: RubyMotion
 
Road to mobile w/ Sinatra, jQuery Mobile, Spine.js and Mustache
Road to mobile w/ Sinatra, jQuery Mobile, Spine.js and MustacheRoad to mobile w/ Sinatra, jQuery Mobile, Spine.js and Mustache
Road to mobile w/ Sinatra, jQuery Mobile, Spine.js and Mustache
 
Trellis Framework At RubyWebConf
Trellis Framework At RubyWebConfTrellis Framework At RubyWebConf
Trellis Framework At RubyWebConf
 
Integrallis groovy-cloud
Integrallis groovy-cloudIntegrallis groovy-cloud
Integrallis groovy-cloud
 
Ferret
FerretFerret
Ferret
 
Bitter Java, Sweeten with JRuby
Bitter Java, Sweeten with JRubyBitter Java, Sweeten with JRuby
Bitter Java, Sweeten with JRuby
 
Ruby Metaprogramming 08
Ruby Metaprogramming 08Ruby Metaprogramming 08
Ruby Metaprogramming 08
 

Recently uploaded

Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 

Recently uploaded (20)

Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 

Rspec and Capybara Intro Tutorial at RailsConf 2013

  • 1. by Brian Sam-Bodden @bsbodden RSpec & Capybara BDD & Acceptance Testing in Rails http://www.integrallis.com https://dl.dropboxusercontent.com/u/2968596/rspec_and_capybara.pdf
  • 2.
  • 3. Objectives Overview & Objectives RSpec & Capybara • Practical Behaviour-Driven Development • Test-Driven Development with RSpec • To become comfortable with the common tools used by Rubyists • To learn and embrace the practices of successful Ruby/Rails developers
  • 4. Requirements Requirements & Objectives What you’ll need on your system to play along... • Git (http://git-scm.com/) • RVM (https://rvm.io) [Optional] • Ruby 1.9.3 (or 2.0) • RubyGems • Any code/text editor
  • 5. Material Conventions Part 1 - Ruby • This 80 minute training consists of a mix of lecture time, guided exercises and some labs (in class if we have the time, take home if we don’t) • For the guided exercises you will see a green “follow along” sign on the slides • For the labs you’ll see an orange sign with the lab number
  • 7. Testing A Means To An End “Our highest priority is to satisfy the customer through early and continuous delivery of valuable software” http://agilemanifesto.org/principles.html
  • 8. Testing A Means To An End • Testing traditionally done at the end of development “if time permitted” (hello waterfall) • No language support or frameworks (back in the old days) • Started from the “inside” with Unit Testing Frameworks • Lots of well tested units, we were still left with a mess at the outer layers • BDD came in to try to reverse the testing approach http://c2.com/cgi/wiki?TenYearsOfTestDrivenDevelopment
  • 9. Testing A Means To An End • BDD testing frameworks are DSLs (built on top of Unit Testing Frameworks) to “get the words rights” • Most examples still use Units (class & methods) to teach BDD. Therefore developers still start at the inside. • Rails showed early own that Web Application Testing CAN be automated • Integration testing still hard to define for most developers • Acceptance testing is NOT integration testing (unless you mean integrating with your users) http://c2.com/cgi/wiki?TenYearsOfTestDrivenDevelopment
  • 10. Request Handling The Request-Response Pipeline Model project.rb Controller projects_controller.rb View projects/index.html.erb Router 2 4 1 5 3 6 7 /projects #index @projects = Project.all @projects HTML select * from projects... HTML 8 1. User requests /projects 2. Rails router forwards the request to projects_controller#index action 3. The index action creates the instance variable @projects by using the Project model all method 4. The all method is mapped by ActiveRecord to a select statement for your DB 5. @projects returns back with a collection of all Project objects 6. The index action renders the index.html.erb view 7. An HTML table of Projects is rendered using ERB (embedded Ruby) which has access to the @projects variable 8. The HTML response is returned to the User
  • 11. Outside-in Testing, BDD/TDD, Unit, Integration & Acceptance in one picture
  • 13. BDD Behavior Driven Development • BDD focuses TDD to deliver the maximum value possible to stakeholders • BDD is a refinement in the language and tooling used for TDD • As the name implies with BDD we focus on behavior specifications • Typically BDD works from the outside in, that is starting with the parts of the software whose behavior is directly perceive by the user • We say BDD refines TDD in that there is an implicit decoupling of the tests and the implementation (i.e.. don’t tests implementation specifics, test perceived behavior)
  • 14. BDD Behavior Driven Development • BDD focuses on “specifications” that describe the behavior of the system • In the process of fleshing out a story the specifications start from the outside and might move towards the inside based on need • In the context of a Web Application this Outside-In approach typically means that we are starting with specifications related to the User Interface • If we are talking about a software component then we mean the API for said component
  • 15. BDD Behavior Driven Development • BDD helps us figure out what to test, where to start and what to ignore (or what to make a target of opportunity) • What to test? ➜ Use Cases or User Stories, test what something does (behavior) rather than what something is (structure) • Where to start? ➜ From the outer most layer • What to ignore? ➜ Anything else... Until proven that you can’t
  • 16. BDD Behavior Driven Development • BDD focuses on getting the words right, the resulting specifications become an executable/self-verifying form of documentation • BDD specifications follow a format that makes them easy to be driven by your system’s User Stories As a [role], I want [goal] so that [benefit] Given [role and its state] When [an event/action occurs] Then [the benefit] User Story Specification
  • 18. RSpec Ruby’s BDD Framework • RSpec is the most popular BDD framework for Ruby • Created by Steven Baker in 2005, enhanced and maintained by David Chelimsky until late 2012 • RSpec provides a DSL to write executable examples of the expected behavior of a piece of code in a controlled context
  • 19. RSpec Ruby’s BDD Framework • RSpec uses the method describe to create and Example Group • Example groups can be nested using the describe or context methods describe Bowling, "#score" do it "returns 0 for all gutter game" do bowling = Bowling.new 20.times { bowling.hit(0) } expect(bowling.score).to eq(0) end end Example Group Example ExpectationMatcher
  • 20. RSpec Matchers • RSpec comes built in with a nice collection of matchers, including: be_true # passes if actual is truthy (not nil or false) be_false # passes if actual is falsy (nil or false) be_nil # passes if actual is nil be # passes if actual is truthy (not nil or false) expect { ... }.to raise_error expect { ... }.to raise_error(ErrorClass) expect { ... }.to raise_error("message") expect { ... }.to raise_error(ErrorClass, "message") expect { ... }.to throw_symbol expect { ... }.to throw_symbol(:symbol) expect { ... }.to throw_symbol(:symbol, 'value') be_xxx # passes if actual.xxx? have_xxx(:arg) # passes if actual.has_xxx?(:arg)
  • 21. RSpec Matchers • and ... https://www.relishapp.com/rspec/rspec-expectations/v/2-13/docs/built-in-matchers be_empty be(expected) # passes if actual.equal?(expected) eq(expected) # passes if actual == expected == expected # passes if actual == expected eql(expected) # passes if actual.eql?(expected) equal(expected) # passes if actual.equal?(expected) be > expected be >= expected be <= expected be < expected =~ /expression/ match(/expression/) be_within(delta).of(expected) be_instance_of(expected) be_kind_of(expected)
  • 22. Test-Driven Development Drive your Development with Tests • TDD is not *really* about testing • TDD is a design technique • TDD leads to cleaner code with separation of concerns • Cleaner code is more reliable and easier to maintain (Duh)
  • 23. Test-Driven Development Drive your Development with Tests • TDD creates a tight loop of development that cognitively engages us • TDD gives us lightweight rigor by making development, goal-oriented with a clear goal setting, goal reaching and improvement stages • The stages of TDD are commonly known as the Red-Green-Refactor loop
  • 24. Test-Driven Development Drive your Development with Tests • The Red-Green-Refactor Loop: Write a failing test for new functionality RED GREENREFACTOR Write the minimal code to pass the testClean up & improve without adding functionality
  • 25. Test-Driven Development Evolve your Code with Tests • Let’s work through a simple TDD/BDD exercise using RSpec • We’ll design a simple shopping cart class • We’ll start by creating a new folder for our exercise and adding a .rvmrc file and a Gemfile />mkdir rspec-follow-along />cd rspec-follow-along />echo 'rvm use 1.9.3@rspec-follow-along' > .rvmrc />touch Gemfile />mkdir spec />mkdir lib source 'https://rubygems.org' group :test do gem 'rspec' end
  • 26. Test-Driven Development Evolve your Code with Tests • With our project configure for RVM and a Gemfile in place we can reenter the directory to activate the Gemset and run the bundle command: />cd .. />cd rspec-follow-along/ Using /Users/user/.rvm/gems/ruby-1.9.3-p374 with gemset rspec-follow-along bsb in ~/Courses/code/rspec-follow-along using ruby-1.9.3-p374@rspec-follow-along /> bundle Using diff-lcs (1.1.3) Using rspec-core (2.12.2) Using rspec-expectations (2.12.1) Using rspec-mocks (2.12.2) Using rspec (2.12.0) Using bundler (1.2.3) Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
  • 27. describe Cart do end Test-Driven Development Evolve your Code with Tests • We’ll start the RGR loop with the simplest possible failure: ”There is no Cart!” • Create the file cart_spec.rb in the spec directory with the following contents:
  • 28. Test-Driven Development Evolve your Code with Tests • Let’s run the specs using the rspec command and passing the spec directory as an argument • Have we arrived at the RED state in our red-green-refactor cycle? />rspec spec /Users/bsb/Courses/code/rspec-follow-along/spec/cart_spec.rb:1:in `<top (required)>': uninitialized constant Cart (NameError) Hint: if you have a failure with no tests it typically means that you need a test (but let’s ignore that for a second...)
  • 29. class Cart end Test-Driven Development Evolve your Code with Tests • Let’s create the Cart class in a /lib folder and require it in our spec: /> rspec spec No examples found. Finished in 0.00006 seconds 0 examples, 0 failures require_relative '../lib/cart.rb' describe Cart do end • Now we have no failures but also we have no specs...
  • 30. Test-Driven Development Evolve your Code with Tests • Let’s craft our first real test to drive the development of the Cart • The spec to tackle is: “An instance of Cart when new contains no items” require_relative '../lib/cart.rb' describe Cart do context "a new cart" do it "contains no items" do expect(@cart).to be_empty end end end
  • 31. Test-Driven Development Evolve your Code with Tests • If we run the specs we can see a failure: /> rspec spec F Failures: 1) Cart a new cart contains no items Failure/Error: expect(@cart).to be_empty NoMethodError: undefined method `empty?' for nil:NilClass # ./spec/cart_spec.rb:6:in `block (3 levels) in <top (required)> Finished in 0.00243 seconds 1 example, 1 failure Now we have our first “real” test-driven failure (and that is a good thing!)
  • 32. Test-Driven Development Evolve your Code with Tests • One of the mantras of BDD is to “get the words right” • If you noticed on the last run the spec output read as “Cart a new cart contains no items” • RSpec is flexible enough to allow us to pass a string to be prefixed to the describe block to make tailor the output to our needs require_relative '../lib/cart.rb' describe "An instance of", Cart do context "when new" do it "contains no items" do expect(@cart).to be_empty end end end
  • 33. Test-Driven Development Evolve your Code with Tests • If we run the specs we can see that the output now matches the desire spec wording /> rspec spec F Failures: 1) An instance of Cart when new contains no items Failure/Error: expect(@cart).to be_empty NoMethodError: undefined method `empty?' for nil:NilClass # ./spec/cart_spec.rb:6:in `block (3 levels) in <top (required)>' Finished in 0.00154 seconds 1 example, 1 failure Failed examples: rspec ./spec/cart_spec.rb:5 # An instance of Cart when new contains no items
  • 34. Test-Driven Development Evolve your Code with Tests • The output shows that we have two failures, one implicit and one explicit • Explicit Failure: We are assuming that a cart has an #empty? method • Implicit Failure: The instance variable @cart has not been initialized Failures: 1) An instance of Cart when new contains no items Failure/Error: expect(@cart).to be_empty NoMethodError: undefined method `empty?' for nil:NilClass # ./spec/cart_spec.rb:6:in `block (3 levels) in <top (required)>'
  • 35. Test-Driven Development Evolve your Code with Tests • We’ll start by addressing the fact that our test fixture hasn’t been setup • Just adding the line @cart = Cart.new wouldn’t be very TDDish • What we should do is first make the failure explicit by writing a test for it! require_relative '../lib/cart.rb' describe "An instance of", Cart do it "should be properly initialized" do expect(@cart).to be_a(Cart) end ... Remember our initial failure with no tests?
  • 36. Test-Driven Development Evolve your Code with Tests • Now we have two valid failing tests to pass, let’s get on with it! ... 1) An instance of Cart should be properly initialized Failure/Error: expect(@cart).to be_a(Cart) expected nil to be a kind of Cart # ./spec/cart_spec.rb:6:in `block (2 levels) in <top (required)>' 2) An instance of Cart when new contains no items Failure/Error: expect(@cart).to be_empty NoMethodError: undefined method `empty?' for nil:NilClass # ./spec/cart_spec.rb:11:in `block (3 levels) in <top (required)>' Finished in 0.00233 seconds 2 examples, 2 failures
  • 37. Test-Driven Development Evolve your Code with Tests • We’ll pass the test by adding the line @cart = Cart.new in a before-each block: describe "An instance of", Cart do before :each do @cart = Cart.new end ... 1) An instance of Cart when new contains no items Failure/Error: expect(@cart).to be_empty NoMethodError: undefined method `empty?' for #<Cart:0x007fc98316cb60> ...
  • 38. Test-Driven Development Evolve your Code with Tests • Let’s add a skeleton empty? method to the Cart class: class Cart def empty? nil end end ... 1) An instance of Cart when new contains no items Failure/Error: expect(@cart).to be_empty expected empty? to return true, got nil # ./spec/cart_spec.rb:15:in `block (3 levels) in <top (required)>' ...
  • 39. Test-Driven Development Evolve your Code with Tests • Now we can comply with the spec by providing an implementation of our Cart • In this case we are using a Hash to hold our items and delegating to the @items#empty? method class Cart def initialize @items = {} end def empty? @items.empty? end end /> rspec spec .. Finished in 0.00196 seconds 2 examples, 0 failures We’ve reached the GREEN state
  • 40. Test-Driven Development Drive your Development with Tests • In the REFACTOR state we concentrate on making the current implementation better, cleaner and more robust • It is very likely that early on in the development there won’t be much to refactor • The need for refactoring is a side-effect of increasing complexity and interaction between classes and subsystems • Refactoring can also introduce implementation specific specs or reveal holes in your previous specs
  • 41. Test-Driven Development Evolve your Code with Tests • Let’s use Ruby’s Forwardable module to simplify the delegation of the collection methods to the @items Hash: class Cart extend Forwardable def_delegator :@items, :empty? def initialize @items = {} end end />rspec spec .. Finished in 0.00365 seconds 2 examples, 0 failures
  • 42. Test-Driven Development RSpec Command • The RSpec command provides several arguments to tailor the run and output of your specifications • For example to see the group and example names in the output use --format documentation /> rspec --format documentation An instance of Cart should be properly initialized when new contains no items Finished in 0.00224 seconds 2 examples, 0 failures
  • 43. Lab 1.0 TDD & BDD • Lab 1.0 consists of 4 specs to be implemented in a TDD fashion: • “An new and empty cart total value should be $0.0” • “An empty cart should no longer be empty after adding an item” • “A cart with items should have a total value equal to the sum of each items’ value times its quantity” • “Increasing the quantity of an item should not increase the Carts’ unique items count”
  • 45. Acceptance Acceptance Testing • Proper acceptance tests treat your application as a black box • They should know as little as possible about what happens under the hood • They’re just there to interact with the interface and observe the results • Jeff Casimir says... “A great testing strategy is to extensively cover the data layer with unit tests then skip all the way up to acceptance tests. This approach gives great code coverage and builds a test suite that can flex with a changing codebase.”
  • 46. Capybara Acceptance test framework for web applications • Capybara is a lightweight alternative to Cucumber • Capybara is a browser automation library • Helps you test web applications by simulating how a real user would interact with your app • It is agnostic about the driver running your tests and comes with Rack::Test and Selenium support built in • WebKit is supported through an external gem
  • 47. RSpec, Capybara, and Steak Acceptance test framework for web applications • Many developers don’t want to bother with Cucumber • They want outside-in testing without the translation step • The Steak project integrated RSpec and Capybara directly • Now we can write acceptance tests just like you write unit tests, greatly simplifying the process • In late 2010 the Capybara absorbed the Steak syntax
  • 48. Rack::Test Acceptance test framework for web applications • Capybara uses Rack::Test by default • Rack::Test interacts with your app at the Rack level • It runs requests against your app, then provides the resulting HTML to Capybara and RSpec for examination. • Rack::Test is completely headless (and therefore fast) • The disadvantage is that it doesn’t process JavaScript (or give you visual feedback) • To test JavaScript in your acceptance tests you can use the selenium-webdriver or capybara-webkit driver.
  • 49. Capybara DSL How to Drive the Browser • The folks at ThoughtBot put a nice Capybara Cheat Sheet https://learn.thoughtbot.com/test-driven-rails-resources/capybara.pdf
  • 50. Capybara DSL How to Drive the Browser https://learn.thoughtbot.com/test-driven-rails-resources/capybara.pdf
  • 51. Capybara DSL How to Drive the Browser https://learn.thoughtbot.com/test-driven-rails-resources/capybara.pdf
  • 52. Acceptance Testing w/ Capybara Testing a Rails Application • We are going to mimic a user’s interaction with a very simple Rails app • The bulk of the functionality in the app will be provided by the devise (authentication) library and the high_voltage (static pages) gems • To concentrate on the subtleties of Capybara we will test an existing application • Let start by using git to clone the master branch of the repository at https://github.com/integrallis/learn-rspec-capybara />git clone git://github.com/integrallis/learn-rspec-capybara.git
  • 53. Acceptance Testing w/ Capybara Testing a Rails Application • CD in and out of the application to activate the RVM Gemset • Bundle the application (bundle install), migrate it (rake db:migrate), prepare the test database (rake db:test:prepare) and launch it (rails s) />rails s => Booting WEBrick => Rails 3.2.13 application starting in development on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server [2013-04-29 10:21:05] INFO WEBrick 1.3.1 [2013-04-29 10:21:05] INFO ruby 1.9.3 (2013-02-22) [x86_64-darwin12.2.1] [2013-04-29 10:21:05] INFO WEBrick::HTTPServer#start: pid=87936 port=3000
  • 54. Acceptance Testing w/ Capybara Testing a Rails Application • Let’s examine the application by opening the URL http://localhost:3000 on a capable browser • All pages are locked until we register on the Sign Up Page (provided by devise): Sign Up Page - /users/sign_up
  • 55. Acceptance Testing w/ Capybara Testing a Rails Application • Once you are signed up you are redirected to the home page and shown a flash message: Home Page - /
  • 56. Acceptance Testing w/ Capybara Testing a Rails Application • About and home pages are ERB templates served by high_voltage: About Page - /about
  • 57. Acceptance Testing w/ Capybara Testing a Rails Application • The user profile page (provided by devise): User Profile Page - /users/edit
  • 58. Acceptance Testing w/ Capybara Testing a Rails Application • The Sign In Page (also provided by devise): Sign In Page - /users/sign_in
  • 59. Acceptance Testing w/ Capybara Testing a Rails Application • If we run the specs using rspec you’ll see two passing specs and the rest as pending: />rspec User should require email to be set should require case sensitive unique value for email Flash Notices can be dismissed by the user (PENDING: No reason given) User Registration failure displays an error message (PENDING: No reason given) shows the correct navigation links (PENDING: No reason given) success displays a welcome message (PENDING: No reason given)
  • 60. Acceptance Testing w/ Capybara Testing a Rails Application • Let’s examine the two passing specs: require 'spec_helper' describe User do it { should validate_presence_of(:email) } it { should validate_uniqueness_of(:email) } end • They’re just simple validation messages via shoulda-matchers
  • 61. Acceptance Testing w/ Capybara Testing a Rails Application • Let’s start by tacking the Sessions Spec, specifically a successful login: context "success" do before do # sign in end it "displays a welcome message" do pending end it "shows the correct navigation links" do # should not see 'Sign in' and 'Sign up' # should see 'Profile' or 'Sign out' pending end end /spec/features/sessions_spec.rb
  • 62. Acceptance Testing w/ Capybara Testing a Rails Application • In the before block we’ll fill in the email and passwords field and click the sign in button: context "success" do before do fill_in 'Email', with: email fill_in 'Password', with: password click_button 'Sign in' end ... end /spec/features/sessions_spec.rb Change and Run your specs!
  • 63. Acceptance Testing w/ Capybara Testing a Rails Application • Capybara provides us with the “page” object which we can inspect, for example, with the have_content method: it "displays a welcome message" do expect(page).to have_content('Signed in successfully.') end /spec/features/sessions_spec.rb Change and Run your specs!
  • 64. Acceptance Testing w/ Capybara Testing a Rails Application • We can also check for certain links to be or not be present in the page: it "shows the correct navigation links" do within('.navbar') do expect(page).to have_link('Profile') expect(page).to have_link('Sign out') expect(page).to_not have_link('Sign in') expect(page).to_not have_link('Sign up') end end /spec/features/sessions_spec.rb Change and Run your specs!
  • 65. Acceptance Testing w/ Capybara Testing a Rails Application • Next let’s tackle the flash notices spec. Notice that in the before block we use the visit method with a Rails named route: require 'spec_helper' describe "Flash Notices", js: true do before do # When an unauthenticated user visit the edit_user_registration_path they # are redirected with a flash notice visit edit_user_registration_path end it "can be dismissed by the user" do # check that the flash message exists click to close the flash message # check that the flash message is gone pending end end /spec/features/flash_notices.rb
  • 66. Acceptance Testing w/ Capybara Testing a Rails Application • First, we’ll check that the text of the flash message has appeared on the page: it "can be dismissed by the user" do expect(page).to have_content("You need to sign in or sign up before continuing.") end /spec/features/flash_notices.rb
  • 67. Acceptance Testing w/ Capybara Testing a Rails Application • Next will, find the alert div using the class CSS selector • Inside of the alert div will find the close HREF and click it it "can be dismissed by the user" do expect(page).to have_content("You need to sign in or sign up before continuing.") within('.alert') do find('.close').click end end /spec/features/flash_notices.rb
  • 68. Acceptance Testing w/ Capybara Testing a Rails Application • Now, we check that the content of the flash alert is no longer on the page: it "can be dismissed by the user" do expect(page).to have_content("You need to sign in or sign up before continuing.") within('.alert') do find('.close').click end expect(page).to_not have_content("You need to sign in or sign up before continuing.") end /spec/features/flash_notices.rb
  • 69. Lab 2.0 Capybara • In Lab 2.0, complete the remaining acceptance specs: • The Registrations Spec in /spec/features/registrations_spec.rb • The Cancel Registration Spec in /spec/features/cancel_registration.rb
  • 70. Conclusions & Objectives Practice, Practice, Practice • Don’t take TDD & BDD as dogma. Find ways to make it work for you! • I don’t always use TDD & BDD but when I do ... • If you can TDD/BDD keep the code local until you can check it in with a corresponding test