1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
|
Feature: set
As a rails developer willing to speed-up my integration tests
In order to take advantage of examples running in transactions
I want to use #set that store the data before all example and
reload active record objects before each examples
Scenario: Examples run in transactions (no side effects between examples)
Given a file named "spec/models/widget_spec.rb" with:
"""
require "spec_helper"
describe Widget do
set(:widget) { Widget.create!(:name => 'widget_1') }
subject { widget }
context "when name is changed to 'widget_2" do
before do
widget.update_attributes!(:name => 'widget_2')
end
its(:name) { should == 'widget_2' }
end
context "when name is 'widget_1" do
its(:name) { should == 'widget_1' }
end
end
"""
When I run "rspec spec/models/widget_spec.rb"
Then the examples should all pass
Scenario: We can use sub sub contexts just fine
Given a file named "spec/models/widget_spec.rb" with:
"""
require "spec_helper"
describe Widget do
set(:widget) { Widget.create(:name => 'apple') }
subject { widget }
context "when name is changed to 'banana" do
before do
widget.update_attributes!(:name => 'banana')
end
its(:name) { should == 'banana' }
context "when we append ' is good'" do
before do
widget.name << ' is good'
widget.save!
end
its(:name) { should == 'banana is good' }
end
context "when we append ' is bad'" do
before do
widget.name << ' is bad'
widget.save!
end
its(:name) { should == 'banana is bad' }
context "when we append ' for you'" do
before do
widget.name << ' for you'
widget.save!
end
its(:name) { should == 'banana is bad for you' }
end
end
end
context "when name is 'apple" do
its(:name) { should == 'apple' }
end
end
"""
When I run "rspec spec/models/widget_spec.rb"
Then the examples should all pass
Scenario: I can delete an object, it will be available in the next example.
Given a file named "spec/models/widget_spec.rb" with:
"""
require "spec_helper"
describe Widget do
set(:widget) { Widget.create(:name => 'apple') }
subject { widget }
context "when I destroy the widget" do
before do
widget.destroy
end
it "should be destroyed" do
Widget.find_by_id(widget.id).should be_nil
end
end
context "when name is 'apple" do
its(:name) { should == 'apple' }
end
end
"""
When I run "rspec spec/models/widget_spec.rb"
Then the examples should all pass
Scenario: I can update a model in a before block
Scenario: I can use a set model in another set definition
|