1 require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
3 describe "Scenario loading" do
4 it "should load from configured directories" do
9 it "should raise Scenario::NameError when the scenario does not exist" do
10 lambda { Scenario.load(:whatcha_talkin_bout) }.should raise_error(Scenario::NameError)
13 it "should allow us to add helper methods through the helpers class method" do
14 klass = :empty.to_scenario
20 klass.new.methods.should include('hello')
23 it "should load the scenarios only once per test class/example group, then unload at the end, even on exception of any test" do
24 tracking_scenario = Class.new((:things).to_scenario) do
25 cattr_accessor :instance
27 raise "Should only be created once" if self.class.instance
28 self.class.instance = super(*args)
32 test_case = Class.new(Test::Unit::TestCase) do
33 scenario tracking_scenario
34 def test_something; end
42 tracking_scenario.instance.should be_unloaded
45 it "should provide a built-in scenario named :blank which clears all tables found in schema.rb" do
51 describe Scenarios::TableMethods do
54 it "should understand namespaced models" do
55 create_record "ModelModule::Model", :raking, :name => "Raking", :description => "Moving leaves around"
56 models(:raking).should_not be_nil
59 it "should include record creation methods" do
60 create_record(:thing, :three, :name => "Three")
61 things(:three).name.should == "Three"
64 it "should include other example helper methods" do
65 create_thing("The Thing")
66 things(:the_thing).name.should == "The Thing"
69 describe "for retrieving objects" do
70 it "should have a pluralized name" do
71 should respond_to("things")
72 should_not respond_to("thing")
75 it "should answer a single object given a single name" do
76 things(:one).should be_kind_of(Thing)
77 things("one").should be_kind_of(Thing)
78 things(:two).name.should == "two"
81 it "should answer an array of objects given multiple names" do
82 things(:one, :two).should be_kind_of(Array)
83 things(:one, :two).should eql([things(:one), things(:two)])
86 it "should just return the argument if an AR instance is given" do
88 things(thing).should eql(thing)
92 describe "for retrieving ids" do
93 it "should have a singular name" do
94 should respond_to("thing_id")
95 should_not respond_to("thing_ids")
96 should_not respond_to("things_id")
99 it "should answer a single id given a single name" do
100 thing_id(:one).should be_kind_of(Fixnum)
101 thing_id("one").should be_kind_of(Fixnum)
104 it "should answer an array of ids given multiple names" do
105 thing_id(:one, :two).should be_kind_of(Array)
106 thing_id(:one, :two).should eql([thing_id(:one), thing_id(:two)])
107 thing_id("one", "two").should eql([thing_id(:one), thing_id(:two)])
110 it "should answer the id of the argument if an AR instance id given" do
112 thing_id(thing).should == thing.id
117 describe "it uses people and things scenarios", :shared => true do
118 it "should have reader helper methods for each used scenario" do
119 should respond_to(:things)
120 should respond_to(:people)
123 it "should allow us to use helper methods from each scenario inside an example" do
124 should respond_to(:create_thing)
125 should respond_to(:create_person)
129 describe "A composite scenario" do
132 it_should_behave_like "it uses people and things scenarios"
134 it "should allow us to use helper methods scenario" do
135 should respond_to(:method_from_composite_scenario)
139 describe "Multiple scenarios" do
140 scenario :things, :people
142 it_should_behave_like "it uses people and things scenarios"
145 describe "A complex composite scenario" do
146 scenario :complex_composite
148 it_should_behave_like "it uses people and things scenarios"
150 it "should have correct reader helper methods" do
151 should respond_to(:places)
154 it "should allow us to use correct helper methods" do
155 should respond_to(:create_place)
159 describe "Overlapping scenarios" do
160 scenario :composite, :things, :people
162 it "should not cause scenarios to be loaded twice" do
163 Person.find_all_by_first_name("John").size.should == 1
167 describe "create_record table method" do
170 it "should automatically set timestamps" do
171 create_record :note, :first, :content => "first note"
173 note.created_at.should be_instance_of(Time)
177 describe "create_model table method" do
180 it "should support symbolic names" do
181 thing = create_model Thing, :mything, :name => "My Thing", :description => "For testing"
182 things(:mything).should == thing
185 it "should blast any table touched as a side effect of creating a model (callbacks, observers, etc.)" do
186 create_model SideEffectyThing
187 blasted_tables.should include(Thing.table_name)