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 ein...
1 class TaskTest < ActiveSupport::TestCase
2
3   test 'Test::Unit is rocking' do
4     assert Test::Unit.rocking?
5   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...
Model Specs
 1 describe Task do
 2
 3   describe 'validation' do
 4
 5     before do
 6       @task = Task.new(:title => '...
Controller Specs
 1 describe TasksController do
 2
 3   describe 'handling GET /tasks' do
 4
 5     it quot;should render ...
View Specs
 1 describe 'tasks/index' do
 2
 3   before do
 4     @task = stub_model(Task)
 5     assigns[:tasks] = [@task]...
Demo
Shared Examples (1)
 1 describe 'a secure action', :shared => true do
 2
 3   describe 'without a logged-in user' do
 4
 5...
Shared Examples (2)
 1 describe TasksController do
 2
 3   describe 'handling GET /tasks' do
 4
 5     it_should_behave_li...
Demo
Matchers
 1 class RequireAttributeMatcher
 2
 3     def initialize(attribute)
 4       @attribute = attribute
 5     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 th...
Stories (Cucumber)
 1   Given /^that there are no tasks$/ do
 2     Task.destroy_all
 3   end
 4
 5   When /^I create task...
Demo
Installation

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

ruby script/plugin install git://github.c...
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://githu...
Upcoming SlideShare
Loading in...5
×

RSpec

2,426

Published on

overview of RSpec

Published in: Technology
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,426
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
38
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

RSpec

  1. 1. RSpec
  2. 2. Freelancer • http://simplabs.com • http://xing.com/profile/Marco_OtteWitte • http://github.com/marcoow
  3. 3. Buzzwords TDD
  4. 4. Buzzwords X TDD
  5. 5. Buzzwords XTDD BDD
  6. 6. BDD
  7. 7. BDD Beschreiben von Verhalten
  8. 8. BDD Beschreiben von Verhalten mit natürlicher Sprache bzw. Domänen- Sprache
  9. 9. BDD Beschreiben von Verhalten mit natürlicher Sprache bzw. Domänen- Sprache Spezifikation und (Regressions)- Tests in einem
  10. 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. 11. 1 describe RSpec do 2 3 it 'should be rocking' do 4 RSpec.should be_rocking 5 end 6 7 end
  12. 12. Syntactic Sugar RSpec.should be_rocking => RSpec.rocking?
  13. 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. 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. 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. 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. 17. Demo
  18. 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. 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. 20. Demo
  21. 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. 22. Demo
  23. 23. Stories (Cucumber) Given [Context] When [Aktion] Then [Business Value!]
  24. 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. 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. 26. Demo
  27. 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. 28. Autotest sudo gem install ZenTest RSPEC=true autotest RSPEC=true AUTOFEATURE=true autotest
  29. 29. Demo
  30. 30. Report [spec/rspec.opts] --format html:doc/spec/report.html
  31. 31. Q&A
  32. 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
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×