scenarios 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -0
- data/lib/scenarios.rb +2 -9
- data/lib/scenarios/base.rb +1 -12
- data/lib/scenarios/scenario.rb +5 -48
- data/scenarios.gemspec +66 -0
- data/test/base_test.rb +3 -59
- data/test/scenario_test.rb +6 -59
- data/test/scenarios_test.rb +5 -7
- data/test/system_test.rb +7 -48
- metadata +4 -2
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.1
|
data/lib/scenarios.rb
CHANGED
@@ -2,18 +2,11 @@ module Scenarios
|
|
2
2
|
|
3
3
|
#
|
4
4
|
# Register a Scenario instance with the module.
|
5
|
-
# Scenarios are stored inside of scenario groups.
|
6
5
|
#
|
7
|
-
# When multple scenarios are registerd in a single
|
8
|
-
# group, it looks like this:
|
9
|
-
#
|
10
|
-
# { :user_scenarios => { :no_users => [Scenario], :admin_users => [Scenario] }}
|
11
|
-
#
|
12
|
-
# @param [String, Symbol] group_name
|
13
6
|
# @param [Scenarios::Scenario] obj
|
14
7
|
#
|
15
|
-
def self.register(
|
16
|
-
|
8
|
+
def self.register(obj)
|
9
|
+
store[obj.name.to_sym] = obj
|
17
10
|
end
|
18
11
|
|
19
12
|
#
|
data/lib/scenarios/base.rb
CHANGED
@@ -8,15 +8,6 @@ module Scenarios
|
|
8
8
|
|
9
9
|
class << self
|
10
10
|
|
11
|
-
#
|
12
|
-
# Define the name for this scenario group
|
13
|
-
#
|
14
|
-
# @param [String, Symbol] group_name
|
15
|
-
#
|
16
|
-
def name(group_name)
|
17
|
-
@group_name = group_name
|
18
|
-
end
|
19
|
-
|
20
11
|
#
|
21
12
|
# Create a new instance of `Scenario` and register it.
|
22
13
|
#
|
@@ -25,10 +16,8 @@ module Scenarios
|
|
25
16
|
# @return [Scenairos::Scenario] the new scenario
|
26
17
|
#
|
27
18
|
def scenario(name, &block)
|
28
|
-
raise "You must call `name` before you can call `scenario`" unless @group_name
|
29
|
-
|
30
19
|
obj = Scenario.new(name, &block)
|
31
|
-
Scenarios.register(
|
20
|
+
Scenarios.register(obj)
|
32
21
|
obj
|
33
22
|
end
|
34
23
|
end
|
data/lib/scenarios/scenario.rb
CHANGED
@@ -2,7 +2,7 @@ module Scenarios
|
|
2
2
|
|
3
3
|
class Scenario
|
4
4
|
|
5
|
-
attr_reader :name
|
5
|
+
attr_reader :name
|
6
6
|
|
7
7
|
#
|
8
8
|
# Initialize the new instance using the block
|
@@ -12,59 +12,16 @@ module Scenarios
|
|
12
12
|
#
|
13
13
|
def initialize(name, &block)
|
14
14
|
@name = name
|
15
|
-
@
|
16
|
-
block.bind(self).call if block_given?
|
15
|
+
@block = block
|
17
16
|
end
|
18
17
|
|
19
18
|
#
|
20
|
-
#
|
19
|
+
# Run the initialization block
|
21
20
|
#
|
22
|
-
# Example:
|
23
|
-
#
|
24
|
-
# setup do
|
25
|
-
# @resorce = User.create(...)
|
26
|
-
# end
|
27
|
-
#
|
28
|
-
# @param [Proc] block
|
29
|
-
#
|
30
|
-
def setup(&block)
|
31
|
-
@setup_block = block
|
32
|
-
end
|
33
|
-
|
34
|
-
#
|
35
|
-
# Call the setup block
|
36
|
-
#
|
37
|
-
def setup!
|
38
|
-
@setup_block.call if @setup_block.is_a?(Proc)
|
39
|
-
end
|
40
|
-
|
41
|
-
#
|
42
|
-
# Save a block that will be used later to
|
43
|
-
# create a particular dataset.
|
44
|
-
#
|
45
|
-
# Example:
|
46
|
-
#
|
47
|
-
# define :params do
|
48
|
-
# { :valid_id => @resource.id }
|
49
|
-
# end
|
50
|
-
#
|
51
|
-
# @param [String, Symbol] key
|
52
21
|
# @param [Proc] block
|
53
22
|
#
|
54
|
-
def
|
55
|
-
@
|
56
|
-
end
|
57
|
-
|
58
|
-
|
59
|
-
#
|
60
|
-
# Evaluate a particular definition and
|
61
|
-
# return the results
|
62
|
-
#
|
63
|
-
# @param [String, Symbol] key Name of definition to eval
|
64
|
-
#
|
65
|
-
def [](key)
|
66
|
-
d = @definitions[key.to_sym]
|
67
|
-
d.is_a?(Proc) ? d.call : nil
|
23
|
+
def generate
|
24
|
+
@block.bind(self).call if @block.is_a?(Proc)
|
68
25
|
end
|
69
26
|
|
70
27
|
end
|
data/scenarios.gemspec
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{scenarios}
|
8
|
+
s.version = "0.1.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Starr Horne"]
|
12
|
+
s.date = %q{2010-06-13}
|
13
|
+
s.description = %q{Factories on steroids.}
|
14
|
+
s.email = %q{starr@chromahq.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"lib/scenarios.rb",
|
27
|
+
"lib/scenarios/base.rb",
|
28
|
+
"lib/scenarios/proc_extensions.rb",
|
29
|
+
"lib/scenarios/scenario.rb",
|
30
|
+
"scenarios.gemspec",
|
31
|
+
"test/base_test.rb",
|
32
|
+
"test/helper.rb",
|
33
|
+
"test/scenario_test.rb",
|
34
|
+
"test/scenarios_test.rb",
|
35
|
+
"test/system_test.rb"
|
36
|
+
]
|
37
|
+
s.homepage = %q{http://github.com/starrhorne/scenarios}
|
38
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
39
|
+
s.require_paths = ["lib"]
|
40
|
+
s.rubygems_version = %q{1.3.6}
|
41
|
+
s.summary = %q{Manage scenarios for testing}
|
42
|
+
s.test_files = [
|
43
|
+
"test/base_test.rb",
|
44
|
+
"test/helper.rb",
|
45
|
+
"test/scenario_test.rb",
|
46
|
+
"test/scenarios_test.rb",
|
47
|
+
"test/system_test.rb"
|
48
|
+
]
|
49
|
+
|
50
|
+
if s.respond_to? :specification_version then
|
51
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
52
|
+
s.specification_version = 3
|
53
|
+
|
54
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
55
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
56
|
+
s.add_development_dependency(%q<mocha>, [">= 0"])
|
57
|
+
else
|
58
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
59
|
+
s.add_dependency(%q<mocha>, [">= 0"])
|
60
|
+
end
|
61
|
+
else
|
62
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
63
|
+
s.add_dependency(%q<mocha>, [">= 0"])
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
data/test/base_test.rb
CHANGED
@@ -2,73 +2,17 @@ require 'helper'
|
|
2
2
|
|
3
3
|
class TestBase < Test::Unit::TestCase
|
4
4
|
|
5
|
-
context "no name" do
|
6
|
-
|
7
|
-
setup do
|
8
|
-
Scenarios.clear
|
9
|
-
Scenarios::Base.name(nil)
|
10
|
-
end
|
11
|
-
|
12
|
-
should "raise an exception when `scenario` called" do
|
13
|
-
assert_raise RuntimeError do
|
14
|
-
Scenarios::Base.scenario("X"){}
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
|
-
context "a name" do
|
21
|
-
|
22
|
-
setup do
|
23
|
-
Scenarios.clear
|
24
|
-
Scenarios::Base.name(:sample)
|
25
|
-
end
|
26
|
-
|
27
|
-
should "not raise an exception when `scenario` called" do
|
28
|
-
Scenarios::Base.scenario("X"){}
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
32
|
-
|
33
5
|
context "a few empty scenarios" do
|
34
6
|
|
35
7
|
setup do
|
36
8
|
Scenarios.clear
|
37
|
-
Scenarios::Base.name(:sample)
|
38
9
|
@one = Scenarios::Base.scenario(:one){}
|
39
10
|
@two = Scenarios::Base.scenario(:two){}
|
40
11
|
end
|
41
12
|
|
42
|
-
should "register
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
should "register both scenarios" do
|
47
|
-
assert_equal 2, Scenarios[:sample].size
|
48
|
-
end
|
49
|
-
|
50
|
-
should "register correct scenarios" do
|
51
|
-
assert_equal({@one.name.to_sym => @one, @two.name.to_sym => @two}, Scenarios[:sample])
|
52
|
-
end
|
53
|
-
|
54
|
-
end
|
55
|
-
|
56
|
-
context "a scenario with a definition" do
|
57
|
-
setup do
|
58
|
-
Scenarios.clear
|
59
|
-
Scenarios::Base.name(:sample)
|
60
|
-
@one = Scenarios::Base.instance_eval %[
|
61
|
-
scenario(:one) do
|
62
|
-
define :foo do
|
63
|
-
{ :bar => :baz }
|
64
|
-
end
|
65
|
-
end
|
66
|
-
]
|
67
|
-
end
|
68
|
-
|
69
|
-
should "add definition to scenerio object" do
|
70
|
-
assert_equal 1, @one.definitions.size
|
71
|
-
assert_equal({ :bar => :baz }, @one.definitions[:foo].call)
|
13
|
+
should "register with Scenarios module" do
|
14
|
+
assert_equal @one, Scenarios[:one]
|
15
|
+
assert_equal @two, Scenarios[:two]
|
72
16
|
end
|
73
17
|
|
74
18
|
end
|
data/test/scenario_test.rb
CHANGED
@@ -2,75 +2,22 @@ require 'helper'
|
|
2
2
|
|
3
3
|
class TestScenario < Test::Unit::TestCase
|
4
4
|
|
5
|
-
context "
|
5
|
+
context "a scenario" do
|
6
6
|
|
7
7
|
setup do
|
8
|
-
@resource = Scenarios::Scenario.new("test")
|
8
|
+
@resource = Scenarios::Scenario.new("test") do
|
9
|
+
"hi"
|
10
|
+
end
|
9
11
|
end
|
10
12
|
|
11
13
|
should "have name set" do
|
12
14
|
assert_equal('test', @resource.name)
|
13
15
|
end
|
14
16
|
|
15
|
-
should "
|
16
|
-
assert_equal(
|
17
|
-
end
|
18
|
-
|
19
|
-
should "return nil on setup" do
|
20
|
-
assert_equal nil, @resource.setup!
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
context "a scenario with a setup block" do
|
26
|
-
|
27
|
-
setup do
|
28
|
-
@resource = Scenarios::Scenario.new("test")
|
29
|
-
@resource.setup do
|
30
|
-
@setup_called = true
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
should "not call setup block automatically" do
|
35
|
-
assert !@setup_called
|
36
|
-
end
|
37
|
-
|
38
|
-
should "call setup block manually, in scope of caller" do
|
39
|
-
@resource.setup!
|
40
|
-
assert @setup_called
|
17
|
+
should "generate correctly" do
|
18
|
+
assert_equal('hi', @resource.generate)
|
41
19
|
end
|
42
20
|
|
43
21
|
end
|
44
22
|
|
45
|
-
context "a scenario with a definition" do
|
46
|
-
|
47
|
-
setup do
|
48
|
-
@resource = Scenarios::Scenario.new("test")
|
49
|
-
@resource.define(:params) do
|
50
|
-
@definition_called = true
|
51
|
-
{}
|
52
|
-
end
|
53
|
-
@resource.define(:other) do
|
54
|
-
{}
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
should "not call definition block automatically" do
|
59
|
-
assert !@definition_called
|
60
|
-
end
|
61
|
-
|
62
|
-
should "call definition block when referenced" do
|
63
|
-
assert_equal({}, @resource[:params])
|
64
|
-
assert @definition_called
|
65
|
-
end
|
66
|
-
|
67
|
-
should "return nil when referencing an invalid definition" do
|
68
|
-
assert_equal(nil, @resource[:winny])
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
23
|
end
|
data/test/scenarios_test.rb
CHANGED
@@ -23,21 +23,19 @@ class TestScenarios < Test::Unit::TestCase
|
|
23
23
|
|
24
24
|
setup do
|
25
25
|
Scenarios.clear
|
26
|
-
@world = stub(:name => :world)
|
27
26
|
@baz = stub(:name => :baz)
|
28
27
|
@foo = stub(:name => :foo)
|
29
|
-
Scenarios.register(
|
30
|
-
Scenarios.register(
|
31
|
-
Scenarios.register("hello", @world)
|
28
|
+
Scenarios.register(@foo)
|
29
|
+
Scenarios.register(@baz)
|
32
30
|
end
|
33
31
|
|
34
32
|
should "return correct store" do
|
35
|
-
assert_equal({:foo =>
|
33
|
+
assert_equal({:foo => @foo, :baz => @baz}, Scenarios.store)
|
36
34
|
end
|
37
35
|
|
38
36
|
should "return correct vals for keys" do
|
39
|
-
assert_equal(
|
40
|
-
assert_equal(
|
37
|
+
assert_equal(@foo, Scenarios[:foo])
|
38
|
+
assert_equal(@baz, Scenarios[:baz])
|
41
39
|
end
|
42
40
|
|
43
41
|
end
|
data/test/system_test.rb
CHANGED
@@ -10,63 +10,22 @@ class TestSystem < Test::Unit::TestCase
|
|
10
10
|
Scenarios.clear
|
11
11
|
|
12
12
|
class SampleScenarios < Scenarios::Base
|
13
|
-
name "sample"
|
14
|
-
|
15
13
|
scenario :one do
|
16
|
-
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
|
-
define :params do
|
21
|
-
{ :foo => @foo }
|
22
|
-
end
|
23
|
-
|
24
|
-
define :env do
|
25
|
-
{ :one => 1, :two => 2, :three => 3 }
|
26
|
-
end
|
27
|
-
|
28
|
-
end.setup!
|
29
|
-
|
30
|
-
scenario :two do
|
31
|
-
setup do
|
32
|
-
@foo = :baz
|
33
|
-
end
|
34
|
-
|
35
|
-
define :params do
|
36
|
-
{ :foo => @foo }
|
37
|
-
end
|
38
|
-
|
39
|
-
end.setup!
|
14
|
+
1
|
15
|
+
end
|
40
16
|
end
|
41
17
|
|
42
18
|
class MoreScenarios < Scenarios::Base
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
setup do
|
47
|
-
@foo = :what
|
48
|
-
end
|
49
|
-
|
50
|
-
define :params do
|
51
|
-
{ :foo => @foo }
|
52
|
-
end
|
53
|
-
end.setup!
|
19
|
+
scenario :two do
|
20
|
+
2
|
21
|
+
end
|
54
22
|
end
|
55
23
|
|
56
24
|
end
|
57
25
|
|
58
|
-
should "register group with module" do
|
59
|
-
assert Scenarios[:sample]
|
60
|
-
end
|
61
|
-
|
62
26
|
should "register scenarios with module" do
|
63
|
-
assert_equal
|
64
|
-
|
65
|
-
|
66
|
-
should "have scenarios return correct values " do
|
67
|
-
assert_equal({:foo => :bar}, Scenarios[:sample][:one][:params])
|
68
|
-
assert_equal({ :one => 1, :two => 2, :three => 3 }, Scenarios[:sample][:one][:env])
|
69
|
-
assert_equal({:foo => :baz}, Scenarios[:sample][:two][:params])
|
27
|
+
assert_equal 1, Scenarios[:one].generate
|
28
|
+
assert_equal 2, Scenarios[:two].generate
|
70
29
|
end
|
71
30
|
|
72
31
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Starr Horne
|
@@ -56,10 +56,12 @@ files:
|
|
56
56
|
- LICENSE
|
57
57
|
- README.rdoc
|
58
58
|
- Rakefile
|
59
|
+
- VERSION
|
59
60
|
- lib/scenarios.rb
|
60
61
|
- lib/scenarios/base.rb
|
61
62
|
- lib/scenarios/proc_extensions.rb
|
62
63
|
- lib/scenarios/scenario.rb
|
64
|
+
- scenarios.gemspec
|
63
65
|
- test/base_test.rb
|
64
66
|
- test/helper.rb
|
65
67
|
- test/scenario_test.rb
|