lawrencepit-machinery 0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/machinery.rb +55 -0
- metadata +53 -0
data/lib/machinery.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
require 'machinery/active_record'
|
3
|
+
|
4
|
+
module Machinery
|
5
|
+
@@scenarios = {}
|
6
|
+
|
7
|
+
def self.scenario(name, &block)
|
8
|
+
@@scenarios[name] = block
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.load(file)
|
12
|
+
self.module_eval(File.read(file))
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
def self.make_scenario(context, names, &block)
|
17
|
+
Machinery::ActiveRecord.record do
|
18
|
+
names.each { |name| context.instance_eval(&@@scenarios[name]) }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
module Helpers
|
23
|
+
def scenario(*names, &block)
|
24
|
+
Machinery.scenario(names.first, &block) and return if block_given?
|
25
|
+
Machinery.make_scenario(self, names, &block)
|
26
|
+
end
|
27
|
+
alias_method :scenarios, :scenario
|
28
|
+
|
29
|
+
def rollback_scenarios
|
30
|
+
Machinery::ActiveRecord.clear
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
module ExampleGroupMacros
|
35
|
+
def scenario(*names, &block)
|
36
|
+
Machinery.scenario(names.first, &block) and return if block_given?
|
37
|
+
self.before(:all) { scenarios(*names) }
|
38
|
+
self.after(:all) { rollback_scenarios }
|
39
|
+
end
|
40
|
+
alias_method :scenarios, :scenario
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
if defined? Spec::Example::ExampleGroup
|
45
|
+
Spec::Example::ExampleGroup.extend Machinery::ExampleGroupMacros
|
46
|
+
Spec::Example::ExampleGroupFactory[nil].__send__('include', Machinery::Helpers)
|
47
|
+
end
|
48
|
+
|
49
|
+
module Test # :nodoc: all
|
50
|
+
module Unit
|
51
|
+
class TestCase
|
52
|
+
include Machinery::Helpers
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
metadata
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lawrencepit-machinery
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "0.3"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lawrence Pit
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-05-16 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: lawrence.pit@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- lib/machinery.rb
|
26
|
+
has_rdoc: false
|
27
|
+
homepage: http://github.com/lawrencepit/machinery
|
28
|
+
post_install_message:
|
29
|
+
rdoc_options: []
|
30
|
+
|
31
|
+
require_paths:
|
32
|
+
- lib
|
33
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: "0"
|
38
|
+
version:
|
39
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
45
|
+
requirements: []
|
46
|
+
|
47
|
+
rubyforge_project:
|
48
|
+
rubygems_version: 1.2.0
|
49
|
+
signing_key:
|
50
|
+
specification_version: 2
|
51
|
+
summary: Machinery to create object graphs.
|
52
|
+
test_files: []
|
53
|
+
|