SlideShare une entreprise Scribd logo
1  sur  32
Télécharger pour lire hors ligne
RSpec
Freelancer


•   http://simplabs.com

•   http://xing.com/profile/Marco_OtteWitte

•   http://github.com/marcoow
Buzzwords

  TDD
Buzzwords

  X
  TDD
Buzzwords

 XTDD

BDD
BDD
BDD
Beschreiben von Verhalten
BDD
Beschreiben von Verhalten

mit natürlicher Sprache bzw.
Domänen- Sprache
BDD
Beschreiben von Verhalten

mit natürlicher Sprache bzw.
Domänen- Sprache

Spezifikation und
(Regressions)- Tests in einem
1 class TaskTest < ActiveSupport::TestCase
2
3   test 'Test::Unit is rocking' do
4     assert Test::Unit.rocking?
5   end
6
7 end
1 describe RSpec do
2
3   it 'should be rocking' do
4     RSpec.should be_rocking
5   end
6
7 end
Syntactic Sugar
RSpec.should be_rocking

=>

RSpec.rocking?
Basics
 1 describe Something do
 2
 3   before do
 4     @thing = Something.new
 5   end
 6
 7   it 'should behave in some way' do
 8     @thing.action.should == 'expected'
 9   end
10
11   after(:all) do
12     Something.destroy_all
13   end
14
15 end
Model Specs
 1 describe Task do
 2
 3   describe 'validation' do
 4
 5     before do
 6       @task = Task.new(:title => 'test task')
 7     end
 8
 9     it 'should succeed when all attributres are set' do
10       @task.should be_valid
11     end
12
13   end
14
15 end
Controller Specs
 1 describe TasksController do
 2
 3   describe 'handling GET /tasks' do
 4
 5     it quot;should render the 'tasks/index' templatequot; do
 6       get :index
 7
 8       response.should render_template('tasks/index')
 9     end
10
12   end
13
14 end
View Specs
 1 describe 'tasks/index' do
 2
 3   before do
 4     @task = stub_model(Task)
 5     assigns[:tasks] = [@task]
 6   end
 7
 8   it 'should render a link to tasks/new' do
 9     render('tasks/index')
10
11     response.should have_tag('a[href=?]', new_task_path)
12   end
13
14 end
Demo
Shared Examples (1)
 1 describe 'a secure action', :shared => true do
 2
 3   describe 'without a logged-in user' do
 4
 5     it 'should redirect to new_session_path' do
 6       do_request
 7
 8       response.should redirect_to(new_session_path)
 9     end
10
11   end
12
13 end
Shared Examples (2)
 1 describe TasksController do
 2
 3   describe 'handling GET /tasks' do
 4
 5     it_should_behave_like 'a secure action'
 6
 7     # => redirect without logged-in user
 8
 9   end
10
11 end
Demo
Matchers
 1 class RequireAttributeMatcher
 2
 3     def initialize(attribute)
 4       @attribute = attribute
 5     end
 6
 7     def matches?(model)
 8       @model = model
 9       model.send(quot;#{@attribute.to_s}=quot;.to_sym, nil)
10       return !model.valid?
11     end
12
13   end
Demo
Stories (Cucumber)

Given [Context]
When   [Aktion]
Then   [Business Value!]
Stories (Cucumber)
Scenario: Create Task
Given that there are no tasks
When I create task quot;task 1quot;
When I go to the tasks page
Then I should see quot;task 1quot;
Stories (Cucumber)
 1   Given /^that there are no tasks$/ do
 2     Task.destroy_all
 3   end
 4
 5   When /^I create task quot;(.*)quot;$/ do |title|
 6     post tasks_url, :task => { :title => title }
 7   end
 8
 9   When /^I go to the tasks page$/ do
10     get tasks_url
11   end
12
13   Then /^I should see quot;(.*)quot;$/ do |title|
14     response.body.should =~ /#{title}/m
15   end
Demo
Installation

ruby script/plugin install git://github.com/
dchelimsky/rspec.git

ruby script/plugin install git://github.com/
dchelimsky/rspec-rails.git

ruby script/generate rspec
Autotest

sudo gem install ZenTest

RSPEC=true autotest

RSPEC=true AUTOFEATURE=true autotest
Demo
Report
[spec/rspec.opts]

--format html:doc/spec/report.html
Q&A
Ressourcen
•   http://rspec.simplabs.com

•   http://rspec.info/

•   http://github.com/dchelimsky/rspec

•   http://github.com/dchelimsky/rspec-rails

•   http://github.com/aslakhellesoy/cucumber

•   http://dannorth.net/introducing-bdd

Contenu connexe

Tendances

Java script object model
Java script object modelJava script object model
Java script object modelJames Hsieh
 
Workshop 5: JavaScript testing
Workshop 5: JavaScript testingWorkshop 5: JavaScript testing
Workshop 5: JavaScript testingVisual Engineering
 
Getting to Grips with SilverStripe Testing
Getting to Grips with SilverStripe TestingGetting to Grips with SilverStripe Testing
Getting to Grips with SilverStripe TestingMark Rickerby
 
SilverStripe CMS JavaScript Refactoring
SilverStripe CMS JavaScript RefactoringSilverStripe CMS JavaScript Refactoring
SilverStripe CMS JavaScript RefactoringIngo Schommer
 
React.js or why DOM finally makes sense
React.js or why DOM finally makes senseReact.js or why DOM finally makes sense
React.js or why DOM finally makes senseEldar Djafarov
 
Angular server-side communication
Angular server-side communicationAngular server-side communication
Angular server-side communicationAlexe Bogdan
 
Unit testing with mocha
Unit testing with mochaUnit testing with mocha
Unit testing with mochaRevath S Kumar
 
Unit testing JavaScript using Mocha and Node
Unit testing JavaScript using Mocha and NodeUnit testing JavaScript using Mocha and Node
Unit testing JavaScript using Mocha and NodeJosh Mock
 
Workshop 14: AngularJS Parte III
Workshop 14: AngularJS Parte IIIWorkshop 14: AngularJS Parte III
Workshop 14: AngularJS Parte IIIVisual Engineering
 
Testing Ruby with Rspec (a beginner's guide)
Testing Ruby with Rspec (a beginner's guide)Testing Ruby with Rspec (a beginner's guide)
Testing Ruby with Rspec (a beginner's guide)Vysakh Sreenivasan
 
I18n
I18nI18n
I18nsoon
 
Python for AngularJS
Python for AngularJSPython for AngularJS
Python for AngularJSJeff Schenck
 
Optimizing a large angular application (ng conf)
Optimizing a large angular application (ng conf)Optimizing a large angular application (ng conf)
Optimizing a large angular application (ng conf)A K M Zahiduzzaman
 
Integrating React.js with PHP projects
Integrating React.js with PHP projectsIntegrating React.js with PHP projects
Integrating React.js with PHP projectsIgnacio Martín
 
정오의 데이트 for iOS 코드 정리
정오의 데이트 for iOS 코드 정리정오의 데이트 for iOS 코드 정리
정오의 데이트 for iOS 코드 정리태준 김
 
JavaScript Unit Testing with Jasmine
JavaScript Unit Testing with JasmineJavaScript Unit Testing with Jasmine
JavaScript Unit Testing with JasmineRaimonds Simanovskis
 
Angular2 & ngrx/store: Game of States
Angular2 & ngrx/store: Game of StatesAngular2 & ngrx/store: Game of States
Angular2 & ngrx/store: Game of StatesOren Farhi
 
Workshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testingWorkshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testingVisual Engineering
 

Tendances (20)

Java script object model
Java script object modelJava script object model
Java script object model
 
Workshop 5: JavaScript testing
Workshop 5: JavaScript testingWorkshop 5: JavaScript testing
Workshop 5: JavaScript testing
 
Getting to Grips with SilverStripe Testing
Getting to Grips with SilverStripe TestingGetting to Grips with SilverStripe Testing
Getting to Grips with SilverStripe Testing
 
SilverStripe CMS JavaScript Refactoring
SilverStripe CMS JavaScript RefactoringSilverStripe CMS JavaScript Refactoring
SilverStripe CMS JavaScript Refactoring
 
React.js or why DOM finally makes sense
React.js or why DOM finally makes senseReact.js or why DOM finally makes sense
React.js or why DOM finally makes sense
 
Angular server-side communication
Angular server-side communicationAngular server-side communication
Angular server-side communication
 
Unit testing with mocha
Unit testing with mochaUnit testing with mocha
Unit testing with mocha
 
Unit testing JavaScript using Mocha and Node
Unit testing JavaScript using Mocha and NodeUnit testing JavaScript using Mocha and Node
Unit testing JavaScript using Mocha and Node
 
Workshop 14: AngularJS Parte III
Workshop 14: AngularJS Parte IIIWorkshop 14: AngularJS Parte III
Workshop 14: AngularJS Parte III
 
Introduction to Redux
Introduction to ReduxIntroduction to Redux
Introduction to Redux
 
Testing Ruby with Rspec (a beginner's guide)
Testing Ruby with Rspec (a beginner's guide)Testing Ruby with Rspec (a beginner's guide)
Testing Ruby with Rspec (a beginner's guide)
 
I18n
I18nI18n
I18n
 
Workshop 10: ECMAScript 6
Workshop 10: ECMAScript 6Workshop 10: ECMAScript 6
Workshop 10: ECMAScript 6
 
Python for AngularJS
Python for AngularJSPython for AngularJS
Python for AngularJS
 
Optimizing a large angular application (ng conf)
Optimizing a large angular application (ng conf)Optimizing a large angular application (ng conf)
Optimizing a large angular application (ng conf)
 
Integrating React.js with PHP projects
Integrating React.js with PHP projectsIntegrating React.js with PHP projects
Integrating React.js with PHP projects
 
정오의 데이트 for iOS 코드 정리
정오의 데이트 for iOS 코드 정리정오의 데이트 for iOS 코드 정리
정오의 데이트 for iOS 코드 정리
 
JavaScript Unit Testing with Jasmine
JavaScript Unit Testing with JasmineJavaScript Unit Testing with Jasmine
JavaScript Unit Testing with Jasmine
 
Angular2 & ngrx/store: Game of States
Angular2 & ngrx/store: Game of StatesAngular2 & ngrx/store: Game of States
Angular2 & ngrx/store: Game of States
 
Workshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testingWorkshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testing
 

En vedette

Getting Answers to Your Testing Questions
Getting Answers to Your Testing QuestionsGetting Answers to Your Testing Questions
Getting Answers to Your Testing Questionsjasnow
 
Straight Up RSpec
Straight Up RSpecStraight Up RSpec
Straight Up RSpecgsterndale
 
RSpec 3.0: Under the Covers
RSpec 3.0: Under the CoversRSpec 3.0: Under the Covers
RSpec 3.0: Under the CoversBrian Gesiak
 
RSpec: What, How and Why
RSpec: What, How and WhyRSpec: What, How and Why
RSpec: What, How and WhyRatan Sebastian
 
Tdd with rspec.md
Tdd with rspec.mdTdd with rspec.md
Tdd with rspec.mdLeo Chang
 
Straight Up RSpec 3 - a neat Ruby BDD tool
Straight Up RSpec 3 - a neat Ruby BDD toolStraight Up RSpec 3 - a neat Ruby BDD tool
Straight Up RSpec 3 - a neat Ruby BDD toolgsterndale
 
The WHY behind TDD/BDD and the HOW with RSpec
The WHY behind TDD/BDD and the HOW with RSpecThe WHY behind TDD/BDD and the HOW with RSpec
The WHY behind TDD/BDD and the HOW with RSpecBen Mabey
 
RSpec 3: The new, the old, the good
RSpec 3: The new, the old, the goodRSpec 3: The new, the old, the good
RSpec 3: The new, the old, the goodmglrnm
 

En vedette (13)

Getting Answers to Your Testing Questions
Getting Answers to Your Testing QuestionsGetting Answers to Your Testing Questions
Getting Answers to Your Testing Questions
 
Straight Up RSpec
Straight Up RSpecStraight Up RSpec
Straight Up RSpec
 
Wrong
WrongWrong
Wrong
 
TDD with RSpec
TDD with RSpecTDD with RSpec
TDD with RSpec
 
RSpec 3.0: Under the Covers
RSpec 3.0: Under the CoversRSpec 3.0: Under the Covers
RSpec 3.0: Under the Covers
 
RSpec: What, How and Why
RSpec: What, How and WhyRSpec: What, How and Why
RSpec: What, How and Why
 
Rspec 101
Rspec 101Rspec 101
Rspec 101
 
Tdd with rspec.md
Tdd with rspec.mdTdd with rspec.md
Tdd with rspec.md
 
Straight Up RSpec 3 - a neat Ruby BDD tool
Straight Up RSpec 3 - a neat Ruby BDD toolStraight Up RSpec 3 - a neat Ruby BDD tool
Straight Up RSpec 3 - a neat Ruby BDD tool
 
Test Driven
Test DrivenTest Driven
Test Driven
 
RSpec. Part 3
RSpec. Part 3RSpec. Part 3
RSpec. Part 3
 
The WHY behind TDD/BDD and the HOW with RSpec
The WHY behind TDD/BDD and the HOW with RSpecThe WHY behind TDD/BDD and the HOW with RSpec
The WHY behind TDD/BDD and the HOW with RSpec
 
RSpec 3: The new, the old, the good
RSpec 3: The new, the old, the goodRSpec 3: The new, the old, the good
RSpec 3: The new, the old, the good
 

Similaire à RSpec

How To Test Everything
How To Test EverythingHow To Test Everything
How To Test Everythingnoelrap
 
Ruby on Rails testing with Rspec
Ruby on Rails testing with RspecRuby on Rails testing with Rspec
Ruby on Rails testing with RspecBunlong Van
 
ES6 Simplified
ES6 SimplifiedES6 Simplified
ES6 SimplifiedCarlos Ble
 
Introduction to unit testing
Introduction to unit testingIntroduction to unit testing
Introduction to unit testingArtem Shoobovych
 
Ruby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code style
Ruby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code styleRuby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code style
Ruby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code styleAnton Shemerey
 
Ruby Metaprogramming
Ruby MetaprogrammingRuby Metaprogramming
Ruby MetaprogrammingThaichor Seng
 
Una Critica a Rails by Luca Guidi
Una Critica a Rails by Luca GuidiUna Critica a Rails by Luca Guidi
Una Critica a Rails by Luca GuidiCodemotion
 
Blocks by Lachs Cox
Blocks by Lachs CoxBlocks by Lachs Cox
Blocks by Lachs Coxlachie
 
Testing Legacy Rails Apps
Testing Legacy Rails AppsTesting Legacy Rails Apps
Testing Legacy Rails AppsRabble .
 
A Z Introduction To Ruby On Rails
A Z Introduction To Ruby On RailsA Z Introduction To Ruby On Rails
A Z Introduction To Ruby On Railsrailsconf
 
Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl TechniquesDave Cross
 
Refatoração + Design Patterns em Ruby
Refatoração + Design Patterns em RubyRefatoração + Design Patterns em Ruby
Refatoração + Design Patterns em RubyCássio Marques
 
Ruby/Rails
Ruby/RailsRuby/Rails
Ruby/Railsrstankov
 
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasmineSingle Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasminePaulo Ragonha
 

Similaire à RSpec (20)

How To Test Everything
How To Test EverythingHow To Test Everything
How To Test Everything
 
TDD & BDD
TDD & BDDTDD & BDD
TDD & BDD
 
Rspec
RspecRspec
Rspec
 
Why ruby
Why rubyWhy ruby
Why ruby
 
Ruby on Rails testing with Rspec
Ruby on Rails testing with RspecRuby on Rails testing with Rspec
Ruby on Rails testing with Rspec
 
Migrating legacy data
Migrating legacy dataMigrating legacy data
Migrating legacy data
 
ES6 Simplified
ES6 SimplifiedES6 Simplified
ES6 Simplified
 
Introduction to unit testing
Introduction to unit testingIntroduction to unit testing
Introduction to unit testing
 
Ruby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code style
Ruby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code styleRuby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code style
Ruby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code style
 
Ruby Metaprogramming
Ruby MetaprogrammingRuby Metaprogramming
Ruby Metaprogramming
 
Una Critica a Rails by Luca Guidi
Una Critica a Rails by Luca GuidiUna Critica a Rails by Luca Guidi
Una Critica a Rails by Luca Guidi
 
Blocks by Lachs Cox
Blocks by Lachs CoxBlocks by Lachs Cox
Blocks by Lachs Cox
 
Testing Legacy Rails Apps
Testing Legacy Rails AppsTesting Legacy Rails Apps
Testing Legacy Rails Apps
 
A Z Introduction To Ruby On Rails
A Z Introduction To Ruby On RailsA Z Introduction To Ruby On Rails
A Z Introduction To Ruby On Rails
 
A-Z Intro To Rails
A-Z Intro To RailsA-Z Intro To Rails
A-Z Intro To Rails
 
Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl Techniques
 
Refatoração + Design Patterns em Ruby
Refatoração + Design Patterns em RubyRefatoração + Design Patterns em Ruby
Refatoração + Design Patterns em Ruby
 
Ruby/Rails
Ruby/RailsRuby/Rails
Ruby/Rails
 
Well
WellWell
Well
 
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasmineSingle Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
 

Dernier

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 

Dernier (20)

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 

RSpec

  • 2. Freelancer • http://simplabs.com • http://xing.com/profile/Marco_OtteWitte • http://github.com/marcoow
  • 6. BDD
  • 8. BDD Beschreiben von Verhalten mit natürlicher Sprache bzw. Domänen- Sprache
  • 9. BDD Beschreiben von Verhalten mit natürlicher Sprache bzw. Domänen- Sprache Spezifikation und (Regressions)- Tests in einem
  • 10. 1 class TaskTest < ActiveSupport::TestCase 2 3 test 'Test::Unit is rocking' do 4 assert Test::Unit.rocking? 5 end 6 7 end
  • 11. 1 describe RSpec do 2 3 it 'should be rocking' do 4 RSpec.should be_rocking 5 end 6 7 end
  • 13. Basics 1 describe Something do 2 3 before do 4 @thing = Something.new 5 end 6 7 it 'should behave in some way' do 8 @thing.action.should == 'expected' 9 end 10 11 after(:all) do 12 Something.destroy_all 13 end 14 15 end
  • 14. Model Specs 1 describe Task do 2 3 describe 'validation' do 4 5 before do 6 @task = Task.new(:title => 'test task') 7 end 8 9 it 'should succeed when all attributres are set' do 10 @task.should be_valid 11 end 12 13 end 14 15 end
  • 15. Controller Specs 1 describe TasksController do 2 3 describe 'handling GET /tasks' do 4 5 it quot;should render the 'tasks/index' templatequot; do 6 get :index 7 8 response.should render_template('tasks/index') 9 end 10 12 end 13 14 end
  • 16. View Specs 1 describe 'tasks/index' do 2 3 before do 4 @task = stub_model(Task) 5 assigns[:tasks] = [@task] 6 end 7 8 it 'should render a link to tasks/new' do 9 render('tasks/index') 10 11 response.should have_tag('a[href=?]', new_task_path) 12 end 13 14 end
  • 17. Demo
  • 18. Shared Examples (1) 1 describe 'a secure action', :shared => true do 2 3 describe 'without a logged-in user' do 4 5 it 'should redirect to new_session_path' do 6 do_request 7 8 response.should redirect_to(new_session_path) 9 end 10 11 end 12 13 end
  • 19. Shared Examples (2) 1 describe TasksController do 2 3 describe 'handling GET /tasks' do 4 5 it_should_behave_like 'a secure action' 6 7 # => redirect without logged-in user 8 9 end 10 11 end
  • 20. Demo
  • 21. Matchers 1 class RequireAttributeMatcher 2 3 def initialize(attribute) 4 @attribute = attribute 5 end 6 7 def matches?(model) 8 @model = model 9 model.send(quot;#{@attribute.to_s}=quot;.to_sym, nil) 10 return !model.valid? 11 end 12 13 end
  • 22. Demo
  • 23. Stories (Cucumber) Given [Context] When [Aktion] Then [Business Value!]
  • 24. Stories (Cucumber) Scenario: Create Task Given that there are no tasks When I create task quot;task 1quot; When I go to the tasks page Then I should see quot;task 1quot;
  • 25. Stories (Cucumber) 1 Given /^that there are no tasks$/ do 2 Task.destroy_all 3 end 4 5 When /^I create task quot;(.*)quot;$/ do |title| 6 post tasks_url, :task => { :title => title } 7 end 8 9 When /^I go to the tasks page$/ do 10 get tasks_url 11 end 12 13 Then /^I should see quot;(.*)quot;$/ do |title| 14 response.body.should =~ /#{title}/m 15 end
  • 26. Demo
  • 27. Installation ruby script/plugin install git://github.com/ dchelimsky/rspec.git ruby script/plugin install git://github.com/ dchelimsky/rspec-rails.git ruby script/generate rspec
  • 28. Autotest sudo gem install ZenTest RSPEC=true autotest RSPEC=true AUTOFEATURE=true autotest
  • 29. Demo
  • 31. Q&A
  • 32. Ressourcen • http://rspec.simplabs.com • http://rspec.info/ • http://github.com/dchelimsky/rspec • http://github.com/dchelimsky/rspec-rails • http://github.com/aslakhellesoy/cucumber • http://dannorth.net/introducing-bdd