Scenes is a Rails plugin to set up system scenes, mainly for use with Cucumber, but can also be used to set your system into a preset state. Initially this was developed to allow us to set up complex scenarios for our Cucumber stories. Currently, this will only work if you are using ActiveRecord in your Rails app.
From the root of your Rails app:
script/plugin install git://github.com/barrym/scenes.git
Characters are used to represent objects in the database.
Any method of initially creating an object can be used, as long as the created object is returned.
Scenes::Character.named("Alice") {
User.create(:name => 'Alice', :age => 21)
}
Referencing a character is done as follows
Scenes::Character['Alice']
The first time a character is referenced, it is created in the database, all times after that the object is retreived from the database.
You can load in a character and change the default values by passing a block to the .with method
Scenes::Character['Alice'].with do |alice|
alice.age = 25
end
This is equivalent to creating a record in the database and then updating it.
Scenes are used to set the system up in a specific state.
Scenes::Scene.named("Alice and Bob") {
Scenes::Character['Alice']
Scenes::Character['Bob']
}
Scenes don’t have to only contain characters, anything that can be played back can go in a scene.
Scenes can be run using the play method.
Scenes::Scene['Alice and Bob'].play
This will execute the scene, in this case adding Alice and Bob to the database.
There are two rake tasks available:
rake scenes
rake scenes:save
rake scenes will give you a list of the scenes you have set up, choose an entry to load the scene in your development environment – this will delete whatever you currently have in your dev environment (it will run rake db:migrate:reset)
rake scenes:save will save your current development environment as a scene for you to use. This is quite simplistic, and currently almost certainly won’t work with any kind of database constraints you may have, but should work for most cases.
In your env.rb file, add the following
Scenes::load
This will load your scenes from the scenes directory.
If your scenes are stored in another location, just pass the location to Scenes::load
Scenes::load("../shared/scenes/my_scenes.rb")
To use scenes in a story add this to your env.rb
Given /^the scene "#(.+)"$/i do |scene_name|
Scenes::Scene[scene_name].play
end
which allows you to load scenes in a scenario
Given the scene "my great scene"
And I am logged in as the admin user
...
Copyright © 2008 Barry Mitchelson, released under the MIT license