SlideShare a Scribd company logo
10/1/2015
Getting Started with
RSpec…Capybara and whatnot
Lightning Talk hosted by The Firehose Project
Myo Thant Kyaw
What exactly is RSpec?
Behavioral Driven Development
(TDD + Domain Driven Design + Acceptance Test-Driven Planning)
RSpec
Given some context -> When some event occurs -> Then I expect some outcome
DHH’s dislike about RSpec
https://twitter.com/dhh/status/472072157821169664
http://brandonhilkert.com/blog/7-reasons-why-im-sticking-with-minitest-and-fixture
Basic Structure (Syntax)
Given some context -> When some event occurs -> Then I expect some o
Structure:
Given
RSpec.describe StaticPagesController, :type => :controller do
describe "GET index" do
it "renders the index template" do
get :index
expect(response).to render_template("index")
end
end
end
When
Then
WhenGiven Then
RSpec with Ruby
#1: $ gem install rspec
#2: Inside project folder: $ rspec —init
and set up like this
#3: spec/spec_helper.rb >
require_relative '../car'
#4: spec/car_spec.rb >
require 'spec_helper'
describe Car do
before(:each) do
@car = Car.new("Make", "Model", :type)
end
describe "#honk" do
it "returns the correct sound" do
expect(@car.honk).to eq("Ponk ponk")
end
end
#5: $ rspec spec/car_spec.rb -fd
Some RSpec Matchers
✤ expect(@car.make).to eq(“Honda”)
✤ expect(@car.make).to match(/H.n.a/)
✤ expect(@visible).to be(true)
✤ expect(@numbers).to match_array([4,5,2,8])
✤ expect(alphabet).to start_with("a")
✤ expect(alphabet).to end_with(“z")
✤ expect(alphabet).to start_with("a").and end_with(“z")
✤ expect(stoplight.color).to eq("red").or eq("green").or eq(“yellow")
✤ http://rspec.info/blog/2014/01/new-in-rspec-3-composable-matchers/
✤ RSpec Cheatsheet: http://www.anchor.com.au/wp-content/uploads/rspec_cheatsheet_attributed.pdf
RSpec with Rails - 1
Gemfile >
group :development, :test do
gem 'rspec-rails', '~> 3.0'
gem 'factory_girl_rails'
end
group :test do
gem 'faker'
gem 'capybara'
gem 'guard-rspec'
gem 'selenium-webdriver', '~> 2.47.1'
end
$ bundle install
RSpec with Rails - 2
$ rails g rspec:install
Delete > test folder
spec/rails_helper.rb >
require 'capybara/rspec'
Install spec files for existing controllers and models >
$ rails g rspec:controller StaticPagesController
$ rails g rspec:model Course
(RSpec generates spec files automatically upon rails g controller/model)
RSpec with Rails - Controller Test
# controllers/selfies_controller.rb
require 'rails_helper'
RSpec.describe StaticPagesController, :type => :controller do
describe "GET index" do
it "renders the index template" do
get :index
expect(response).to render_template("index")
end
end
describe "GET about" do
it "renders the about page" do
get :about
expect(response).to render_template("about")
end
end
end
Controller Test
RSpec with Rails - Model Test
# spec/models/selfy_spec.rb
require 'rails_helper'
RSpec.describe Selfy, :type => :model do
describe "selfy" do
selfy = FactoryGirl.build(:selfy)
it "has a valid factory title" do
expect(selfy.title).to eq("This is test selfy title")
end
it "has a valid factory description" do
expect(selfy.description).to eq("This is test selfy description")
end
end
Model Test
RSpec with Rails
Feature Test with Capybara -1
# spec/features/user_visits_homepage_spec.rb
require "rails_helper"
RSpec.feature "User visits homepage", :type => :feature do
scenario "successfully", :js => true do
visit root_path
expect(page).to have_text("Welcome to Selfie There")
end
end
Capybara
Selenium JS Web Driver
Feature Test
Capybara Cheatsheet:
https://learn.thoughtbot.com/test-driven-rails-resources/capybara.pdf
(OPTIONAL)
RSpec with Rails
Feature Test with Capybara -2
# spec/features/user_signs_in_spec.rb
require "rails_helper"
RSpec.feature "User signs in", :type => :feature do
scenario "successfully", :js => true do
user = FactoryGirl.build(:user)
visit "/users/sign_in"
fill_in "Email", :with => user.email
fill_in "Password", :with => user.password
click_button "Log in"
expect(page).to have_text("Signed in successfully.")
end
end
Feature Test
Tips and tricks
Know the difference between FactoryGirl.create() and FactoryGirl.build()
If your test says something like email exists
=> $ rake db:test:prepare
Know how fixtures work and maybe use database_cleaner gem to avoid pos
Use guard gem to run automated testing
=> $ guard init and leave the tab open like you are running rails server
some .rspec options
.rspec >
—color
—format documentation
Thank You!!!
Myo Thant Kyaw

More Related Content

What's hot

Linux Porting
Linux PortingLinux Porting
Linux Porting
Anil Kumar Pugalia
 
U-Boot - An universal bootloader
U-Boot - An universal bootloader U-Boot - An universal bootloader
U-Boot - An universal bootloader
Emertxe Information Technologies Pvt Ltd
 
Porting Android
Porting AndroidPorting Android
Porting Android
Opersys inc.
 
Android Binder IPC for Linux
Android Binder IPC for LinuxAndroid Binder IPC for Linux
Android Binder IPC for Linux
Yu-Hsin Hung
 
Bootloaders (U-Boot)
Bootloaders (U-Boot) Bootloaders (U-Boot)
Bootloaders (U-Boot)
Omkar Rane
 
Android : Deep dive into developing MobileApp using Android
Android : Deep dive into developing MobileApp using AndroidAndroid : Deep dive into developing MobileApp using Android
Android : Deep dive into developing MobileApp using Android
Emertxe Information Technologies Pvt Ltd
 
Board Bringup
Board BringupBoard Bringup
Board Bringup
Anil Kumar Pugalia
 
Android Booting Sequence
Android Booting SequenceAndroid Booting Sequence
Android Booting Sequence
Jayanta Ghoshal
 
Cgroups in android
Cgroups in androidCgroups in android
Cgroups in android
ramalinga prasad tadepalli
 
A practical guide to buildroot
A practical guide to buildrootA practical guide to buildroot
A practical guide to buildroot
Emertxe Information Technologies Pvt Ltd
 
Spring Framework
Spring Framework  Spring Framework
Spring Framework
tola99
 
Introduction Linux Device Drivers
Introduction Linux Device DriversIntroduction Linux Device Drivers
Introduction Linux Device Drivers
NEEVEE Technologies
 
Something About Dynamic Linking
Something About Dynamic LinkingSomething About Dynamic Linking
Something About Dynamic Linking
Wang Hsiangkai
 
Spring Boot
Spring BootSpring Boot
Spring Boot
Jaran Flaath
 
Spotify: Automating Cassandra repairs
Spotify: Automating Cassandra repairsSpotify: Automating Cassandra repairs
Spotify: Automating Cassandra repairs
DataStax Academy
 
The Android graphics path, in depth
The Android graphics path, in depthThe Android graphics path, in depth
The Android graphics path, in depth
Chris Simmonds
 
Design and Concepts of Android Graphics
Design and Concepts of Android GraphicsDesign and Concepts of Android Graphics
Design and Concepts of Android Graphics
National Cheng Kung University
 
Introduction to E2E in Cypress
Introduction to E2E in CypressIntroduction to E2E in Cypress
Introduction to E2E in Cypress
Fabio Biondi
 
Explore Android Internals
Explore Android InternalsExplore Android Internals
Explore Android Internals
National Cheng Kung University
 
Understanding Reactive Programming
Understanding Reactive ProgrammingUnderstanding Reactive Programming
Understanding Reactive Programming
Andres Almiray
 

What's hot (20)

Linux Porting
Linux PortingLinux Porting
Linux Porting
 
U-Boot - An universal bootloader
U-Boot - An universal bootloader U-Boot - An universal bootloader
U-Boot - An universal bootloader
 
Porting Android
Porting AndroidPorting Android
Porting Android
 
Android Binder IPC for Linux
Android Binder IPC for LinuxAndroid Binder IPC for Linux
Android Binder IPC for Linux
 
Bootloaders (U-Boot)
Bootloaders (U-Boot) Bootloaders (U-Boot)
Bootloaders (U-Boot)
 
Android : Deep dive into developing MobileApp using Android
Android : Deep dive into developing MobileApp using AndroidAndroid : Deep dive into developing MobileApp using Android
Android : Deep dive into developing MobileApp using Android
 
Board Bringup
Board BringupBoard Bringup
Board Bringup
 
Android Booting Sequence
Android Booting SequenceAndroid Booting Sequence
Android Booting Sequence
 
Cgroups in android
Cgroups in androidCgroups in android
Cgroups in android
 
A practical guide to buildroot
A practical guide to buildrootA practical guide to buildroot
A practical guide to buildroot
 
Spring Framework
Spring Framework  Spring Framework
Spring Framework
 
Introduction Linux Device Drivers
Introduction Linux Device DriversIntroduction Linux Device Drivers
Introduction Linux Device Drivers
 
Something About Dynamic Linking
Something About Dynamic LinkingSomething About Dynamic Linking
Something About Dynamic Linking
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Spotify: Automating Cassandra repairs
Spotify: Automating Cassandra repairsSpotify: Automating Cassandra repairs
Spotify: Automating Cassandra repairs
 
The Android graphics path, in depth
The Android graphics path, in depthThe Android graphics path, in depth
The Android graphics path, in depth
 
Design and Concepts of Android Graphics
Design and Concepts of Android GraphicsDesign and Concepts of Android Graphics
Design and Concepts of Android Graphics
 
Introduction to E2E in Cypress
Introduction to E2E in CypressIntroduction to E2E in Cypress
Introduction to E2E in Cypress
 
Explore Android Internals
Explore Android InternalsExplore Android Internals
Explore Android Internals
 
Understanding Reactive Programming
Understanding Reactive ProgrammingUnderstanding Reactive Programming
Understanding Reactive Programming
 

Similar to Rspec presentation

Rspec and Capybara Intro Tutorial at RailsConf 2013
Rspec and Capybara Intro Tutorial at RailsConf 2013Rspec and Capybara Intro Tutorial at RailsConf 2013
Rspec and Capybara Intro Tutorial at RailsConf 2013
Brian Sam-Bodden
 
RSpec and Rails
RSpec and RailsRSpec and Rails
RSpec and Rails
Alan Hecht
 
Rspec
RspecRspec
Spark View Engine (Richmond)
Spark View Engine (Richmond)Spark View Engine (Richmond)
Spark View Engine (Richmond)
curtismitchell
 
Ruby on Rails - Introduction
Ruby on Rails - IntroductionRuby on Rails - Introduction
Ruby on Rails - Introduction
Vagmi Mudumbai
 
A tour on ruby and friends
A tour on ruby and friendsA tour on ruby and friends
A tour on ruby and friends
旻琦 潘
 
Capybara and cucumber with DSL using ruby
Capybara and cucumber with DSL using rubyCapybara and cucumber with DSL using ruby
Capybara and cucumber with DSL using ruby
Deepak Chandella
 
Javascript unit testing, yes we can e big
Javascript unit testing, yes we can   e bigJavascript unit testing, yes we can   e big
Javascript unit testing, yes we can e big
Andy Peterson
 
Elasticsearch And Ruby [RuPy2012]
Elasticsearch And Ruby [RuPy2012]Elasticsearch And Ruby [RuPy2012]
Elasticsearch And Ruby [RuPy2012]
Karel Minarik
 
Basic RSpec 2
Basic RSpec 2Basic RSpec 2
Basic RSpec 2
Triet Le Minh
 
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
Codemotion
 
TDC 2012 - Patterns e Anti-Patterns em Ruby
TDC 2012 - Patterns e Anti-Patterns em RubyTDC 2012 - Patterns e Anti-Patterns em Ruby
TDC 2012 - Patterns e Anti-Patterns em Ruby
Fabio Akita
 
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
Udaya Kiran
 
RSpec 3.0: Under the Covers
RSpec 3.0: Under the CoversRSpec 3.0: Under the Covers
RSpec 3.0: Under the Covers
Brian Gesiak
 
RSpec. Part 2
RSpec. Part 2RSpec. Part 2
RSpec. Part 2
Vladimir Dementyev
 
Crossing the Bridge: Connecting Rails and your Front-end Framework
Crossing the Bridge: Connecting Rails and your Front-end FrameworkCrossing the Bridge: Connecting Rails and your Front-end Framework
Crossing the Bridge: Connecting Rails and your Front-end Framework
Daniel Spector
 
Create a new project in ROR
Create a new project in RORCreate a new project in ROR
Create a new project in ROR
akankshita satapathy
 
Ruby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developerRuby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developer
gicappa
 
SCR Annotations for Fun and Profit
SCR Annotations for Fun and ProfitSCR Annotations for Fun and Profit
SCR Annotations for Fun and Profit
Mike Pfaff
 
BDD in iOS with Cedar
BDD in iOS with CedarBDD in iOS with Cedar
BDD in iOS with Cedar
Jason McCreary
 

Similar to Rspec presentation (20)

Rspec and Capybara Intro Tutorial at RailsConf 2013
Rspec and Capybara Intro Tutorial at RailsConf 2013Rspec and Capybara Intro Tutorial at RailsConf 2013
Rspec and Capybara Intro Tutorial at RailsConf 2013
 
RSpec and Rails
RSpec and RailsRSpec and Rails
RSpec and Rails
 
Rspec
RspecRspec
Rspec
 
Spark View Engine (Richmond)
Spark View Engine (Richmond)Spark View Engine (Richmond)
Spark View Engine (Richmond)
 
Ruby on Rails - Introduction
Ruby on Rails - IntroductionRuby on Rails - Introduction
Ruby on Rails - Introduction
 
A tour on ruby and friends
A tour on ruby and friendsA tour on ruby and friends
A tour on ruby and friends
 
Capybara and cucumber with DSL using ruby
Capybara and cucumber with DSL using rubyCapybara and cucumber with DSL using ruby
Capybara and cucumber with DSL using ruby
 
Javascript unit testing, yes we can e big
Javascript unit testing, yes we can   e bigJavascript unit testing, yes we can   e big
Javascript unit testing, yes we can e big
 
Elasticsearch And Ruby [RuPy2012]
Elasticsearch And Ruby [RuPy2012]Elasticsearch And Ruby [RuPy2012]
Elasticsearch And Ruby [RuPy2012]
 
Basic RSpec 2
Basic RSpec 2Basic RSpec 2
Basic RSpec 2
 
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
 
TDC 2012 - Patterns e Anti-Patterns em Ruby
TDC 2012 - Patterns e Anti-Patterns em RubyTDC 2012 - Patterns e Anti-Patterns em Ruby
TDC 2012 - Patterns e Anti-Patterns em Ruby
 
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
 
RSpec 3.0: Under the Covers
RSpec 3.0: Under the CoversRSpec 3.0: Under the Covers
RSpec 3.0: Under the Covers
 
RSpec. Part 2
RSpec. Part 2RSpec. Part 2
RSpec. Part 2
 
Crossing the Bridge: Connecting Rails and your Front-end Framework
Crossing the Bridge: Connecting Rails and your Front-end FrameworkCrossing the Bridge: Connecting Rails and your Front-end Framework
Crossing the Bridge: Connecting Rails and your Front-end Framework
 
Create a new project in ROR
Create a new project in RORCreate a new project in ROR
Create a new project in ROR
 
Ruby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developerRuby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developer
 
SCR Annotations for Fun and Profit
SCR Annotations for Fun and ProfitSCR Annotations for Fun and Profit
SCR Annotations for Fun and Profit
 
BDD in iOS with Cedar
BDD in iOS with CedarBDD in iOS with Cedar
BDD in iOS with Cedar
 

Recently uploaded

UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website
Pixlogix Infotech
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Zilliz
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
Neo4j
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 

Recently uploaded (20)

UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 

Rspec presentation

  • 1. 10/1/2015 Getting Started with RSpec…Capybara and whatnot Lightning Talk hosted by The Firehose Project Myo Thant Kyaw
  • 2. What exactly is RSpec? Behavioral Driven Development (TDD + Domain Driven Design + Acceptance Test-Driven Planning) RSpec Given some context -> When some event occurs -> Then I expect some outcome DHH’s dislike about RSpec https://twitter.com/dhh/status/472072157821169664 http://brandonhilkert.com/blog/7-reasons-why-im-sticking-with-minitest-and-fixture
  • 3. Basic Structure (Syntax) Given some context -> When some event occurs -> Then I expect some o Structure: Given RSpec.describe StaticPagesController, :type => :controller do describe "GET index" do it "renders the index template" do get :index expect(response).to render_template("index") end end end When Then WhenGiven Then
  • 4. RSpec with Ruby #1: $ gem install rspec #2: Inside project folder: $ rspec —init and set up like this #3: spec/spec_helper.rb > require_relative '../car' #4: spec/car_spec.rb > require 'spec_helper' describe Car do before(:each) do @car = Car.new("Make", "Model", :type) end describe "#honk" do it "returns the correct sound" do expect(@car.honk).to eq("Ponk ponk") end end #5: $ rspec spec/car_spec.rb -fd
  • 5. Some RSpec Matchers ✤ expect(@car.make).to eq(“Honda”) ✤ expect(@car.make).to match(/H.n.a/) ✤ expect(@visible).to be(true) ✤ expect(@numbers).to match_array([4,5,2,8]) ✤ expect(alphabet).to start_with("a") ✤ expect(alphabet).to end_with(“z") ✤ expect(alphabet).to start_with("a").and end_with(“z") ✤ expect(stoplight.color).to eq("red").or eq("green").or eq(“yellow") ✤ http://rspec.info/blog/2014/01/new-in-rspec-3-composable-matchers/ ✤ RSpec Cheatsheet: http://www.anchor.com.au/wp-content/uploads/rspec_cheatsheet_attributed.pdf
  • 6. RSpec with Rails - 1 Gemfile > group :development, :test do gem 'rspec-rails', '~> 3.0' gem 'factory_girl_rails' end group :test do gem 'faker' gem 'capybara' gem 'guard-rspec' gem 'selenium-webdriver', '~> 2.47.1' end $ bundle install
  • 7. RSpec with Rails - 2 $ rails g rspec:install Delete > test folder spec/rails_helper.rb > require 'capybara/rspec' Install spec files for existing controllers and models > $ rails g rspec:controller StaticPagesController $ rails g rspec:model Course (RSpec generates spec files automatically upon rails g controller/model)
  • 8. RSpec with Rails - Controller Test # controllers/selfies_controller.rb require 'rails_helper' RSpec.describe StaticPagesController, :type => :controller do describe "GET index" do it "renders the index template" do get :index expect(response).to render_template("index") end end describe "GET about" do it "renders the about page" do get :about expect(response).to render_template("about") end end end Controller Test
  • 9. RSpec with Rails - Model Test # spec/models/selfy_spec.rb require 'rails_helper' RSpec.describe Selfy, :type => :model do describe "selfy" do selfy = FactoryGirl.build(:selfy) it "has a valid factory title" do expect(selfy.title).to eq("This is test selfy title") end it "has a valid factory description" do expect(selfy.description).to eq("This is test selfy description") end end Model Test
  • 10. RSpec with Rails Feature Test with Capybara -1 # spec/features/user_visits_homepage_spec.rb require "rails_helper" RSpec.feature "User visits homepage", :type => :feature do scenario "successfully", :js => true do visit root_path expect(page).to have_text("Welcome to Selfie There") end end Capybara Selenium JS Web Driver Feature Test Capybara Cheatsheet: https://learn.thoughtbot.com/test-driven-rails-resources/capybara.pdf (OPTIONAL)
  • 11. RSpec with Rails Feature Test with Capybara -2 # spec/features/user_signs_in_spec.rb require "rails_helper" RSpec.feature "User signs in", :type => :feature do scenario "successfully", :js => true do user = FactoryGirl.build(:user) visit "/users/sign_in" fill_in "Email", :with => user.email fill_in "Password", :with => user.password click_button "Log in" expect(page).to have_text("Signed in successfully.") end end Feature Test
  • 12. Tips and tricks Know the difference between FactoryGirl.create() and FactoryGirl.build() If your test says something like email exists => $ rake db:test:prepare Know how fixtures work and maybe use database_cleaner gem to avoid pos Use guard gem to run automated testing => $ guard init and leave the tab open like you are running rails server
  • 13. some .rspec options .rspec > —color —format documentation