factory_toys 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +5 -0
- data/.gitignore +22 -0
- data/LICENSE +20 -0
- data/README.rdoc +45 -0
- data/Rakefile +45 -0
- data/VERSION +1 -0
- data/factory_toys.gemspec +62 -0
- data/lib/factory_toys/f_factory.rb +105 -0
- data/lib/factory_toys/parser.rb +51 -0
- data/lib/factory_toys.rb +45 -0
- data/spec/factory_toys/f_factory_spec.rb +78 -0
- data/spec/factory_toys/parser_spec.rb +71 -0
- data/spec/factory_toys_spec.rb +49 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +10 -0
- data/tmp/ffactories/simple_factory.rb +31 -0
- metadata +102 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Thomas Brand
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
= FactoryToys
|
2
|
+
|
3
|
+
This is a idea to help with Feature Management and works in a as a set of
|
4
|
+
feature configuration files that can use ruby to do fancy things and ultimately
|
5
|
+
simplify the process of updating your features.
|
6
|
+
|
7
|
+
The tool is designed to be use where you need to manage large numbers of
|
8
|
+
features which all have very similar featureset (i.e. only one of two difference)
|
9
|
+
|
10
|
+
== Can't I just use Scenario Outlines to do this I hear you ask..
|
11
|
+
|
12
|
+
You some it it you can.. but the things you can't:
|
13
|
+
|
14
|
+
* Use a parameter to slightly change you hook configuration
|
15
|
+
* Output actual features which is my mind makes fixing any breaks in the test
|
16
|
+
easier.
|
17
|
+
|
18
|
+
|
19
|
+
== ToDo
|
20
|
+
|
21
|
+
* Allow scenarios to be built from parts rather than just as a block of text
|
22
|
+
=> allow common parts of features to only be specified once and then shared
|
23
|
+
basically
|
24
|
+
* Add functionality to only rebuild the feature file if there has been a change
|
25
|
+
most likely using fssm once I have a look and understand how it works..
|
26
|
+
* Add other configuration options.. Not really sure what else is needed but
|
27
|
+
am sure somthing will turn up
|
28
|
+
* Fix the readme so it is not quite so much of a ramble.
|
29
|
+
* Add exmaple code to the readme so that people can see how this should work
|
30
|
+
* Add generator so that templates can be generated
|
31
|
+
* Rename the gem to FeatureToys (Did I fcuk up or what)
|
32
|
+
|
33
|
+
== Note on Patches/Pull Requests
|
34
|
+
|
35
|
+
* Fork the project.
|
36
|
+
* Make your feature addition or bug fix.
|
37
|
+
* Add tests for it. This is important so I don't break it in a
|
38
|
+
future version unintentionally.
|
39
|
+
* Commit, do not mess with rakefile, version, or history.
|
40
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
41
|
+
* Send me a pull request. Bonus points for topic branches.
|
42
|
+
|
43
|
+
== Copyright
|
44
|
+
|
45
|
+
Copyright (c) 2010 David Henry & Thomas Brand. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "factory_toys"
|
8
|
+
gem.summary = %Q{Simplify Feature Management}
|
9
|
+
gem.description = %Q{Simplify Feature Management}
|
10
|
+
gem.email = "dw_henry@yahoo.com.au"
|
11
|
+
gem.homepage = "http://github.com/tom025/factory-toys"
|
12
|
+
gem.authors = ["David Henry","Thomas Brand"]
|
13
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'spec/rake/spectask'
|
22
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
23
|
+
spec.libs << 'lib' << 'spec'
|
24
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
25
|
+
end
|
26
|
+
|
27
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
28
|
+
spec.libs << 'lib' << 'spec'
|
29
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
30
|
+
spec.rcov = true
|
31
|
+
end
|
32
|
+
|
33
|
+
task :spec => :check_dependencies
|
34
|
+
|
35
|
+
task :default => :spec
|
36
|
+
|
37
|
+
require 'rake/rdoctask'
|
38
|
+
Rake::RDocTask.new do |rdoc|
|
39
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
40
|
+
|
41
|
+
rdoc.rdoc_dir = 'rdoc'
|
42
|
+
rdoc.title = "factory-toys #{version}"
|
43
|
+
rdoc.rdoc_files.include('README*')
|
44
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
45
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.1
|
@@ -0,0 +1,62 @@
|
|
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{factory_toys}
|
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 = ["David Henry", "Thomas Brand"]
|
12
|
+
s.date = %q{2010-09-15}
|
13
|
+
s.description = %q{Simplify Feature Management}
|
14
|
+
s.email = %q{dw_henry@yahoo.com.au}
|
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
|
+
"factory_toys.gemspec",
|
27
|
+
"lib/factory_toys.rb",
|
28
|
+
"lib/factory_toys/f_factory.rb",
|
29
|
+
"lib/factory_toys/parser.rb",
|
30
|
+
"spec/factory_toys/f_factory_spec.rb",
|
31
|
+
"spec/factory_toys/parser_spec.rb",
|
32
|
+
"spec/factory_toys_spec.rb",
|
33
|
+
"spec/spec.opts",
|
34
|
+
"spec/spec_helper.rb",
|
35
|
+
"tmp/ffactories/simple_factory.rb"
|
36
|
+
]
|
37
|
+
s.homepage = %q{http://github.com/tom025/factory-toys}
|
38
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
39
|
+
s.require_paths = ["lib"]
|
40
|
+
s.rubygems_version = %q{1.3.7}
|
41
|
+
s.summary = %q{Simplify Feature Management}
|
42
|
+
s.test_files = [
|
43
|
+
"spec/factory_toys/f_factory_spec.rb",
|
44
|
+
"spec/factory_toys/parser_spec.rb",
|
45
|
+
"spec/factory_toys_spec.rb",
|
46
|
+
"spec/spec_helper.rb"
|
47
|
+
]
|
48
|
+
|
49
|
+
if s.respond_to? :specification_version then
|
50
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
51
|
+
s.specification_version = 3
|
52
|
+
|
53
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
54
|
+
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
55
|
+
else
|
56
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
57
|
+
end
|
58
|
+
else
|
59
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
@@ -0,0 +1,105 @@
|
|
1
|
+
module FactoryToys
|
2
|
+
class FFactory # Feature Factory
|
3
|
+
attr_accessor :output, :filename
|
4
|
+
attr_accessor :data
|
5
|
+
|
6
|
+
def initialize(filename)
|
7
|
+
@output = ''
|
8
|
+
@filename = filename
|
9
|
+
#build_output(filename)
|
10
|
+
end
|
11
|
+
|
12
|
+
def output(filename)
|
13
|
+
eval(self.data[:base])
|
14
|
+
|
15
|
+
self.build_feature(self.data[:feature])
|
16
|
+
|
17
|
+
locals = self.send(:local_variables)
|
18
|
+
scenarios = locals.find_all{|var| var =~ /_#{FactoryToys.scenarios}$/}
|
19
|
+
scenarios.each do |scenario|
|
20
|
+
options = get_options(scenario)
|
21
|
+
options.each do |option|
|
22
|
+
eval(self.get_option_string(scenario, option))
|
23
|
+
option =~ /^(.+)_#{FactoryToys.scenarios}$/
|
24
|
+
identifier = $1
|
25
|
+
scenario = "#{identifer}_#{FactoryToys.scenario}"
|
26
|
+
raise MissingScenarioError, scenario unless scenarios[scenario]
|
27
|
+
eval(scenarios[scenario])
|
28
|
+
output += scenario + "\n\n"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def add_feature(feature)
|
34
|
+
raise FactoryToys::MissingFeatureDefinitionError if feature.blank?
|
35
|
+
output += feature
|
36
|
+
end
|
37
|
+
|
38
|
+
def add_scenario(scenario, options)
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
def data
|
43
|
+
return @data if @data
|
44
|
+
file = File.open(FactoryToys.source_location + "/" + @filename, 'r')
|
45
|
+
@data = Parser.new(file.read).elements
|
46
|
+
end
|
47
|
+
|
48
|
+
def option_string(scenario, option)
|
49
|
+
return '' unless scenario[:foreach]
|
50
|
+
foreach = get_option_types(scenario[:foreach], false)
|
51
|
+
raise InternalForEachError unless foreach.size == option.size
|
52
|
+
foreach.map(&:to_s).join(', ') + ' = ' + option.map(&:to_s).join(', ')
|
53
|
+
end
|
54
|
+
|
55
|
+
def get_options(scenario)
|
56
|
+
all_options = []
|
57
|
+
if scenario[:foreach]
|
58
|
+
self.get_option_types(scenario[:foreach]).each do |element|
|
59
|
+
raise MissingForeachListError, element.to_s unless scenario[element].is_a?(Array)
|
60
|
+
if all_options.empty?
|
61
|
+
all_options = scenario[element].map{|element_value| [element_value]}
|
62
|
+
else
|
63
|
+
all_options = add_option(all_options, scenario[element])
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
return all_options
|
68
|
+
end
|
69
|
+
|
70
|
+
def add_option(all_options, elements)
|
71
|
+
options = all_options.clone
|
72
|
+
all_options = []
|
73
|
+
elements.each do |element_value|
|
74
|
+
cur_options = options.clone
|
75
|
+
cur_options.map!{|row| [element_value] + row }
|
76
|
+
all_options += cur_options
|
77
|
+
end
|
78
|
+
return all_options
|
79
|
+
end
|
80
|
+
|
81
|
+
def get_option_types(option, reverse=true)
|
82
|
+
return [option] unless option.is_a?(Array)
|
83
|
+
return option unless reverse
|
84
|
+
option.reverse
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
#ing_feature = {
|
90
|
+
# :foreach => [:direction, :settlement_method],
|
91
|
+
# :direction => ['buy', 'sell'],
|
92
|
+
# :settlement_method => [1,2,3]
|
93
|
+
#}
|
94
|
+
#
|
95
|
+
#all_options, options, current_options
|
96
|
+
#[] [] []
|
97
|
+
# [['b'],['s']]
|
98
|
+
#[['b'],['s']] [['b'],['s']] [['b'],['s']]
|
99
|
+
#[] [['b'],['s']] [['b'],['s']]
|
100
|
+
#[] [['b'],['s']] a =[['b',1],['s',1]]
|
101
|
+
#a [['b'],['s']] [['b'],['s']]
|
102
|
+
#a [['b'],['s']] b =[['b',2],['s',2]]
|
103
|
+
#a + b
|
104
|
+
#
|
105
|
+
#all_options = [['b', 1], ['b',2],['b',3],['s',1]...]
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module FactoryToys
|
2
|
+
class Parser # Feature Factory
|
3
|
+
attr_accessor :elements
|
4
|
+
|
5
|
+
def elements
|
6
|
+
@elements ||= {}
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(data)
|
10
|
+
rows = self.split_by_row(data)
|
11
|
+
rows = self.process_elements(rows)
|
12
|
+
elements[:base] = (rows.empty? ? '' : rows.join("\n") )
|
13
|
+
end
|
14
|
+
|
15
|
+
protected
|
16
|
+
def process_elements(rows)
|
17
|
+
row = 0
|
18
|
+
while rows.size > row
|
19
|
+
rows, row = self.process_element(rows, row)
|
20
|
+
end
|
21
|
+
return rows
|
22
|
+
end
|
23
|
+
|
24
|
+
def split_by_row(data)
|
25
|
+
data.split("\n").map(&:strip).find_all{|str| !str.blank?}
|
26
|
+
end
|
27
|
+
|
28
|
+
def process_element(rows, row)
|
29
|
+
if rows[row] =~ /^[\s]*([^\s]+)[\s]*=[\s]*<<-([^\s]+)[\s]*$/
|
30
|
+
name, start_text = $1, $2
|
31
|
+
rows = self.extract_element(rows, row, name, start_text)
|
32
|
+
return rows, row
|
33
|
+
else
|
34
|
+
return rows, row + 1
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def extract_element(rows, row, name, start_text)
|
39
|
+
end_row = find_row(rows, row, start_text)
|
40
|
+
elements[name.to_sym] = rows[row..end_row].join("\n")
|
41
|
+
(row == 0 ? [] : rows[0..row-1]) + rows[end_row+1..-1]
|
42
|
+
end
|
43
|
+
|
44
|
+
def find_row(rows, row, start_text)
|
45
|
+
rows[row..-1].each_with_index do |row_text, i|
|
46
|
+
return row + i if row_text.strip == start_text
|
47
|
+
end
|
48
|
+
raise FactoryToys::CloseTagNotFoundError
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/factory_toys.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
module FactoryToys
|
2
|
+
class MissingEnvironmentError < StandardError; end
|
3
|
+
class CloseTagNotFoundError < StandardError; end
|
4
|
+
class MissingForeachListError < StandardError; end
|
5
|
+
class InternalForEachError < StandardError; end
|
6
|
+
class MissingScenarioError < StandardError; end
|
7
|
+
|
8
|
+
class << self
|
9
|
+
attr_accessor :features_directory, :source_directory
|
10
|
+
attr_accessor :factories
|
11
|
+
attr_accessor :scenario, :scenarios
|
12
|
+
|
13
|
+
def factories
|
14
|
+
@factories ||= []
|
15
|
+
end
|
16
|
+
|
17
|
+
def source_location
|
18
|
+
@source_location = ::RAILS_ROOT + '/' + self.source_directory
|
19
|
+
rescue NameError
|
20
|
+
raise MissingEnvironmentError
|
21
|
+
end
|
22
|
+
|
23
|
+
protected
|
24
|
+
def source_files
|
25
|
+
Dir.glob(self.source_location, '*')
|
26
|
+
rescue Errno::ENOENT => e
|
27
|
+
return "Source Directory Does not exist: #{self.source_directory}"
|
28
|
+
end
|
29
|
+
|
30
|
+
public
|
31
|
+
def update_features
|
32
|
+
self.source_files.each do |file|
|
33
|
+
FactoryToys::FFactory.new(file)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
autoload :FFactory, 'factory_toys/f_factory'
|
39
|
+
autoload :Parser, 'factory_toys/parser'
|
40
|
+
end
|
41
|
+
|
42
|
+
FactoryToys.scenarios = 'feature'
|
43
|
+
FactoryToys.scenario = 'scenario'
|
44
|
+
FactoryToys.features_directory = 'features'
|
45
|
+
FactoryToys.source_directory = 'ffactories'
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
#implemented here to get tests to pass as in Rails Environment and not ruby core??
|
4
|
+
class String
|
5
|
+
def blank?
|
6
|
+
self.nil? or self == ''
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe FactoryToys::FFactory do
|
11
|
+
before do
|
12
|
+
Object.const_set(:RAILS_ROOT, File.dirname(__FILE__) + '/../../tmp') unless Object.const_defined?(:RAILS_ROOT)
|
13
|
+
end
|
14
|
+
|
15
|
+
context '#new' do
|
16
|
+
it 'takes one parameter - filename' do
|
17
|
+
lambda{ FactoryToys::FFactory.new('simple_factory.rb') }.should_not raise_error
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context '#build_output' do
|
22
|
+
it 'calls' do
|
23
|
+
FactoryToys::FFactory.new('simple_factory.rb')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context '#get_options' do
|
28
|
+
it 'with no options' do
|
29
|
+
get_options({}).should == []
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'with a single foreach option' do
|
33
|
+
get_options({:foreach => :opt1, :opt1 => [1,2,3]}).should == [[1],[2],[3]]
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'with two foreach option' do
|
37
|
+
get_options({:foreach => [:opt1, :opt2],
|
38
|
+
:opt1 => [1,2,3],
|
39
|
+
:opt2 => [3,4]}).should ==
|
40
|
+
[[1,3],[1,4],[2,3],[2,4],[3,3],[3,4]]
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'raise error if missing foreach list' do
|
44
|
+
lambda{ get_options({:foreach => :opt1, :opt => [1,2,3]})}.
|
45
|
+
should raise_error FactoryToys::MissingForeachListError
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
def get_options(scenario)
|
50
|
+
FactoryToys::FFactory.new('').get_options(scenario)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context '#option_string' do
|
55
|
+
it 'returns an empty string if no foreach' do
|
56
|
+
option_string({}).should == ''
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'raises an error if option != foreach' do
|
60
|
+
lambda{option_string({:foreach => [:opt1, :opt2]}, [1])}.
|
61
|
+
should raise_error FactoryToys::InternalForEachError
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'returns for one element' do
|
65
|
+
option_string({:foreach => :opt1}, [1]).
|
66
|
+
should == 'opt1 = 1'
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'returns for two elements' do
|
70
|
+
option_string({:foreach => [:opt1, :opt2]}, [1, 2]).
|
71
|
+
should == 'opt1, opt2 = 1, 2'
|
72
|
+
end
|
73
|
+
|
74
|
+
def option_string(scenario, option=[])
|
75
|
+
FactoryToys::FFactory.new('').option_string(scenario, option)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
#implemented here to get tests to pass as in Rails Environment and not ruby core??
|
4
|
+
class String
|
5
|
+
def blank?
|
6
|
+
self.nil? or self == ''
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe FactoryToys::Parser do
|
11
|
+
context 'on initialization' do
|
12
|
+
it 'returns straight text in the under :base' do
|
13
|
+
parser = FactoryToys::Parser.new('hello="hello there"')
|
14
|
+
parser.elements.should ==
|
15
|
+
{:base => 'hello="hello there"'}
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'returns straight text in the under :base with multiple lines' do
|
19
|
+
parser = FactoryToys::Parser.new('hello="hello there"\ngoodbye="bye bye"')
|
20
|
+
parser.elements.should ==
|
21
|
+
{:base => 'hello="hello there"\ngoodbye="bye bye"'}
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'extracting from multi-line comment' do
|
25
|
+
it 'create element for named after variable' do
|
26
|
+
run_factory[:other_string].should_not == nil
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'removes excess white space' do
|
30
|
+
run_factory[:other_string].should == "other_string = <<-TestData\n" +
|
31
|
+
"value=test\n" +
|
32
|
+
"TestData"
|
33
|
+
end
|
34
|
+
|
35
|
+
it "returns unextracted data" do
|
36
|
+
run_factory[:base].should == "test='testing'\ngreeting='Hello Again'"
|
37
|
+
end
|
38
|
+
|
39
|
+
it "removes blank lines" do
|
40
|
+
run_factory("\n\ndate='Dont look at me??'")[:base].should ==
|
41
|
+
"test='testing'\ngreeting='Hello Again'\ndate='Dont look at me??'"
|
42
|
+
end
|
43
|
+
|
44
|
+
it "when named variables only" do
|
45
|
+
string = <<-Data
|
46
|
+
other_string = <<-TestData
|
47
|
+
value=test
|
48
|
+
TestData
|
49
|
+
Data
|
50
|
+
parser = FactoryToys::Parser.new(string)
|
51
|
+
|
52
|
+
parser.elements[:base].should == ''
|
53
|
+
parser.elements[:other_string].should == "other_string = <<-TestData\n" +
|
54
|
+
"value=test\n" +
|
55
|
+
"TestData"
|
56
|
+
end
|
57
|
+
|
58
|
+
def run_factory(additional_text='')
|
59
|
+
string = <<-Data
|
60
|
+
test='testing'
|
61
|
+
other_string = <<-TestData
|
62
|
+
value=test
|
63
|
+
TestData
|
64
|
+
greeting='Hello Again'
|
65
|
+
Data
|
66
|
+
parser = FactoryToys::Parser.new(string + additional_text)
|
67
|
+
parser.elements
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "FactoryToys" do
|
4
|
+
before do
|
5
|
+
Object.const_set(:RAILS_ROOT, File.dirname(__FILE__) + '/../tmp/empty') unless Object.const_defined?(:RAILS_ROOT)
|
6
|
+
end
|
7
|
+
|
8
|
+
context '#update_features' do
|
9
|
+
context 'with missing setup/directroies' do
|
10
|
+
it "raises error if 'RAILS_ROOT' is not defined" do
|
11
|
+
Object.send(:remove_const, :RAILS_ROOT)
|
12
|
+
lambda{ FactoryToys.update_features }.should raise_error FactoryToys::MissingEnvironmentError
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'does nothing if no ffactories directory' do
|
16
|
+
FactoryToys.stub!(:source_files).and_return([])
|
17
|
+
lambda{ FactoryToys.update_features}.should_not raise_error
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'with data/files for processing' do
|
22
|
+
it 'allows custom ffactories directroy' do
|
23
|
+
lambda{ FactoryToys.source_directory = 'myfactories' }.should_not raise_error
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'allows custom features directroy' do
|
27
|
+
lambda{ FactoryToys.features_directory = 'myfeatures' }.should_not raise_error
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'calls Process FFactory for each file' do
|
31
|
+
FactoryToys.stub!(:source_files).and_return(['file1', 'file2'])
|
32
|
+
FactoryToys::FFactory.should_receive(:new).with('file1').and_return(true)
|
33
|
+
FactoryToys::FFactory.should_receive(:new).with('file2').and_return(true)
|
34
|
+
FactoryToys.update_features
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'scenario configuration' do
|
39
|
+
it 'default scenario text' do
|
40
|
+
FactoryToys.scenario.should == 'scenario'
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'default scenarios text' do
|
44
|
+
FactoryToys.scenarios.should == 'feature'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
SETTLEMENT_METHODS = [DCC_DCC = {:buy => 'dcc from dcc', :to => 'dcc to dcc'},
|
2
|
+
REG_REG = {:buy => 'reg from reg', :to => 'reg to reg'}
|
3
|
+
]
|
4
|
+
feature = <<-Data
|
5
|
+
Test Instruction Queue and Processiung
|
6
|
+
In order to ensure the Back Office Processes work as expected
|
7
|
+
Back Office
|
8
|
+
wants to ensure trades process through queues as required
|
9
|
+
Data
|
10
|
+
|
11
|
+
ing_feature = {
|
12
|
+
:foreach => [:direction, :settlement_method],
|
13
|
+
:direction => ['buy', 'sell'],
|
14
|
+
:settlement_method => SETTLEMENT_METHODS
|
15
|
+
}
|
16
|
+
|
17
|
+
ing_scenario = <<-Data1
|
18
|
+
@selenium @#{direction}_trade_ticket_requirements @login_as_middle_office
|
19
|
+
Ing Trade Ticket Instructions - #{direction} #{settlement_method[direction]}
|
20
|
+
Given I am on the Instructions Screen
|
21
|
+
When I click the trade row
|
22
|
+
Then I should see "Instruction Details"
|
23
|
+
When I set Settlement Method to "#{settlement_method[direction]}" for trade
|
24
|
+
Then I should see Settlement Method "#{settlement_method[direction]}" for trade
|
25
|
+
When I follow "Broker Confirm"
|
26
|
+
Then I should see "Instruct Trade"
|
27
|
+
And I should see trade row
|
28
|
+
When I follow "Instruct Trade" with confirmation
|
29
|
+
Then I should not see trade row
|
30
|
+
And Instruction File exists on Hard Drive
|
31
|
+
Data1
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: factory_toys
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 25
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- David Henry
|
14
|
+
- Thomas Brand
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
|
19
|
+
date: 2010-09-15 00:00:00 +01:00
|
20
|
+
default_executable:
|
21
|
+
dependencies:
|
22
|
+
- !ruby/object:Gem::Dependency
|
23
|
+
name: rspec
|
24
|
+
prerelease: false
|
25
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
hash: 13
|
31
|
+
segments:
|
32
|
+
- 1
|
33
|
+
- 2
|
34
|
+
- 9
|
35
|
+
version: 1.2.9
|
36
|
+
type: :development
|
37
|
+
version_requirements: *id001
|
38
|
+
description: Simplify Feature Management
|
39
|
+
email: dw_henry@yahoo.com.au
|
40
|
+
executables: []
|
41
|
+
|
42
|
+
extensions: []
|
43
|
+
|
44
|
+
extra_rdoc_files:
|
45
|
+
- LICENSE
|
46
|
+
- README.rdoc
|
47
|
+
files:
|
48
|
+
- .document
|
49
|
+
- .gitignore
|
50
|
+
- LICENSE
|
51
|
+
- README.rdoc
|
52
|
+
- Rakefile
|
53
|
+
- VERSION
|
54
|
+
- factory_toys.gemspec
|
55
|
+
- lib/factory_toys.rb
|
56
|
+
- lib/factory_toys/f_factory.rb
|
57
|
+
- lib/factory_toys/parser.rb
|
58
|
+
- spec/factory_toys/f_factory_spec.rb
|
59
|
+
- spec/factory_toys/parser_spec.rb
|
60
|
+
- spec/factory_toys_spec.rb
|
61
|
+
- spec/spec.opts
|
62
|
+
- spec/spec_helper.rb
|
63
|
+
- tmp/ffactories/simple_factory.rb
|
64
|
+
has_rdoc: true
|
65
|
+
homepage: http://github.com/tom025/factory-toys
|
66
|
+
licenses: []
|
67
|
+
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options:
|
70
|
+
- --charset=UTF-8
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
hash: 3
|
79
|
+
segments:
|
80
|
+
- 0
|
81
|
+
version: "0"
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
hash: 3
|
88
|
+
segments:
|
89
|
+
- 0
|
90
|
+
version: "0"
|
91
|
+
requirements: []
|
92
|
+
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 1.3.7
|
95
|
+
signing_key:
|
96
|
+
specification_version: 3
|
97
|
+
summary: Simplify Feature Management
|
98
|
+
test_files:
|
99
|
+
- spec/factory_toys/f_factory_spec.rb
|
100
|
+
- spec/factory_toys/parser_spec.rb
|
101
|
+
- spec/factory_toys_spec.rb
|
102
|
+
- spec/spec_helper.rb
|