factory_toys 0.2.2 → 0.2.3

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.2.3
data/factory_toys.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{factory_toys}
8
- s.version = "0.2.2"
8
+ s.version = "0.2.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["David Henry", "Thomas Brand"]
@@ -3,13 +3,18 @@ module FactoryToys
3
3
  attr_accessor :filename
4
4
  attr_accessor :data
5
5
 
6
+ def method_missing(name, *args, &block)
7
+ value = eval("@#{name}")
8
+ return value if value
9
+ super(name, *args, &block)
10
+ end
11
+
6
12
  def initialize(filename)
7
13
  @filename = filename
8
14
 
9
15
  @output = "# Auto Generated Features\n"
10
16
  @output += "# Generated: #{Time.now.to_s}\n"
11
17
  @output += "# Source File: #{@filename}\n\n"
12
-
13
18
  end
14
19
 
15
20
  def write
@@ -21,33 +26,47 @@ module FactoryToys
21
26
 
22
27
  def output
23
28
  eval(self.data[:base])
24
-
25
29
  self.add_feature(self.data[:feature])
26
-
27
- locals = self.send(:local_variables)
28
- scenarios = locals.find_all{|var| var =~ /_#{FactoryToys.scenarios}$/}
29
- scenarios.each do |scenario_name|
30
- feature = eval(scenario_name)
31
- options = get_options(feature)
32
- options.each do |option|
33
- eval(self.option_string(feature, option))
34
- scenario_name =~ /^(.+)_#{FactoryToys.scenarios}$/
35
- identifier = $1
36
- scenario = "#{identifier}_#{FactoryToys.scenario}".to_sym
37
- raise MissingScenarioError, scenario unless self.data[scenario]
38
- eval(self.data[scenario])
39
- @output += eval(scenario.to_s) + "\n\n"
40
- end
41
- end
30
+ conf_names = self.instance_variables
31
+ self.process_file(conf_names)
42
32
  @output
43
33
  end
44
34
 
45
- def add_feature(feature)
46
- raise FactoryToys::MissingFeatureDefinitionError if feature.blank?
47
- eval(feature)
35
+ def add_feature(feature_def)
36
+ raise FactoryToys::MissingFeatureDefinitionError if feature_def.blank?
37
+ eval(feature_def)
48
38
  @output += eval('feature') + "\n\n"
49
39
  end
50
40
 
41
+ def process_file(conf_names)
42
+ scenarios = conf_names.find_all{|var| var =~ /_#{FactoryToys.scenarios}$/}
43
+ scenarios.each do |feature_name|
44
+ self.process_scenarios(feature_name)
45
+ end
46
+ end
47
+
48
+ def process_scenarios(feature_name)
49
+ feature = eval(feature_name)
50
+ options = self.get_options(feature)
51
+ options.each do |option|
52
+ self.add_scenario(feature, option, feature_name)
53
+ end
54
+ end
55
+
56
+ def add_scenario(feature, option, feature_name)
57
+ eval(self.option_string(feature, option))
58
+ scenario_name = self.get_scenario_name(feature_name)
59
+ raise MissingScenarioError, scenario_name unless self.data[scenario_name]
60
+ eval(self.data[scenario_name])
61
+ @output += eval(scenario_name.to_s) + "\n\n"
62
+ end
63
+
64
+ def get_scenario_name(feature_name)
65
+ feature_name =~ /^@(.+)_#{FactoryToys.scenarios}$/
66
+ identifier = $1
67
+ return "#{identifier}_#{FactoryToys.scenario}".to_sym
68
+ end
69
+
51
70
  def data
52
71
  return @data if @data
53
72
  file = File.open(@filename, 'r')
@@ -77,20 +96,21 @@ module FactoryToys
77
96
  end
78
97
 
79
98
  def get_options(scenario)
80
- all_options = []
99
+ all_options = [[]]
81
100
  if scenario[:foreach]
82
101
  self.get_option_types(scenario[:foreach]).each do |element|
83
- raise MissingForeachListError, element.to_s unless scenario[element].is_a?(Array)
84
- if all_options.empty?
85
- all_options = scenario[element].map{|element_value| [element_value]}
86
- else
87
- all_options = add_option(all_options, scenario[element])
88
- end
102
+ all_options = process_options(all_options, scenario[element], element)
89
103
  end
90
104
  end
91
105
  return all_options
92
106
  end
93
107
 
108
+ def process_options(all_options, elements, element)
109
+ raise MissingForeachListError, element.to_s unless elements.is_a?(Array)
110
+ # return elements.map{|element_value| [element_value]} if all_options.empty?
111
+ return self.add_option(all_options, elements)
112
+ end
113
+
94
114
  def add_option(all_options, elements)
95
115
  options = all_options.clone
96
116
  all_options = []
@@ -28,13 +28,24 @@ module FactoryToys
28
28
  def process_element(rows, row)
29
29
  if rows[row] =~ /^[\s]*([^\s]+)[\s]*=[\s]*<<-([^\s]+)[\s]*$/
30
30
  name, start_text = $1, $2
31
+ self.make_instance_variable(rows, row)
31
32
  rows = self.extract_element(rows, row, name, start_text)
32
33
  return rows, row
33
34
  else
35
+ self.make_instance_variable(rows, row)
34
36
  return rows, row + 1
35
37
  end
36
38
  end
37
39
 
40
+ def make_instance_variable(rows, row)
41
+ if rows[row] =~ /^([\s]*)([^\s]+)([\s]*)=(.*)$/
42
+ unless [':','"','"','@'].include?($2[0..0]) or
43
+ ['>'].include?($4[0..0])
44
+ rows[row] = "#{$1}@#{$2}#{$3}=#{$4}"
45
+ end
46
+ end
47
+ end
48
+
38
49
  def extract_element(rows, row, name, start_text)
39
50
  end_row = find_row(rows, row, start_text)
40
51
  elements[name.to_sym] = rows[row..end_row].join("\n")
@@ -20,7 +20,7 @@ describe FactoryToys::FFactory do
20
20
 
21
21
  context '#get_options' do
22
22
  it 'with no options' do
23
- get_options({}).should == []
23
+ get_options({}).should == [[]]
24
24
  end
25
25
 
26
26
  it 'with a single foreach option' do
@@ -12,13 +12,20 @@ describe FactoryToys::Parser do
12
12
  it 'returns straight text in the under :base' do
13
13
  parser = FactoryToys::Parser.new('hello="hello there"')
14
14
  parser.elements.should ==
15
- {:base => 'hello="hello there"'}
15
+ {:base => '@hello="hello there"'}
16
16
  end
17
17
 
18
18
  it 'returns straight text in the under :base with multiple lines' do
19
- parser = FactoryToys::Parser.new('hello="hello there"\ngoodbye="bye bye"')
19
+ parser = FactoryToys::Parser.new("hello='hello there'\ngoodbye='bye bye'")
20
20
  parser.elements.should ==
21
- {:base => 'hello="hello there"\ngoodbye="bye bye"'}
21
+ {:base => "@hello='hello there'\n@goodbye='bye bye'"}
22
+ end
23
+
24
+ it 'does not break hashs' do
25
+ parser = FactoryToys::Parser.new("hello_hash = {\n:hello='hello there',\n:goodbye='bye bye'}")
26
+ parser.elements.should ==
27
+ {:base => "@hello_hash = {\n:hello='hello there',\n:goodbye='bye bye'}"}
28
+
22
29
  end
23
30
 
24
31
  context 'extracting from multi-line comment' do
@@ -27,18 +34,18 @@ describe FactoryToys::Parser do
27
34
  end
28
35
 
29
36
  it 'removes excess white space' do
30
- run_factory[:other_string].should == "other_string = <<-TestData\n" +
37
+ run_factory[:other_string].should == "@other_string = <<-TestData\n" +
31
38
  "value=test\n" +
32
39
  "TestData"
33
40
  end
34
41
 
35
42
  it "returns unextracted data" do
36
- run_factory[:base].should == "test='testing'\ngreeting='Hello Again'"
43
+ run_factory[:base].should == "@test='testing'\n@greeting='Hello Again'"
37
44
  end
38
45
 
39
46
  it "does not remove blank lines" do
40
47
  run_factory("\n\ndate='Dont look at me??'")[:base].should ==
41
- "test='testing'\ngreeting='Hello Again'\n\n\ndate='Dont look at me??'"
48
+ "@test='testing'\n@greeting='Hello Again'\n\n\n@date='Dont look at me??'"
42
49
  end
43
50
 
44
51
  it "when named variables only" do
@@ -50,7 +57,7 @@ Data
50
57
  parser = FactoryToys::Parser.new(string)
51
58
 
52
59
  parser.elements[:base].should == ''
53
- parser.elements[:other_string].should == "other_string = <<-TestData\n" +
60
+ parser.elements[:other_string].should == "@other_string = <<-TestData\n" +
54
61
  "value=test\n" +
55
62
  "TestData"
56
63
  end
@@ -2,7 +2,10 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe "FactoryToys" do
4
4
  before do
5
- Object.const_set(:RAILS_ROOT, Dir.pwd + '/' + File.dirname(__FILE__) + '/../tmp/empty') unless Object.const_defined?(:RAILS_ROOT)
5
+ path = File.dirname(__FILE__)
6
+ path += Dir.pwd + '/' unless path[0..0] == '/'
7
+ Object.send(:remove_const, :RAILS_ROOT) if Object.const_defined?(:RAILS_ROOT)
8
+ Object.const_set(:RAILS_ROOT, path + '/../tmp/empty')
6
9
  end
7
10
 
8
11
  context '#update_features' do
@@ -57,9 +60,11 @@ describe "FactoryToys" do
57
60
 
58
61
  context 'actually produce a file' do
59
62
  it 'creates a file' do
60
- FileUtils.rm_r(FactoryToys.features_location + '/*', :force => true)
61
63
  Object.send(:remove_const, :RAILS_ROOT)
62
- Object.const_set(:RAILS_ROOT, Dir.pwd + '/' + File.dirname(__FILE__) + '/../tmp')
64
+ path = File.dirname(__FILE__)
65
+ path += Dir.pwd + '/' unless path[0..0] == '/'
66
+ Object.const_set(:RAILS_ROOT, path + '/../tmp')
67
+ FileUtils.rm_r(FactoryToys.features_location + '/*', :force => true)
63
68
  FactoryToys.update_features
64
69
  end
65
70
  end
@@ -1,6 +1,6 @@
1
1
  # Auto Generated Features
2
- # Generated: Wed Sep 15 16:47:45 +0100 2010
3
- # Source File: /Users/tom025/rails/factory-toys/./spec/../tmp/ffactories/simple_factory.rb
2
+ # Generated: Wed Sep 15 18:31:15 +0100 2010
3
+ # Source File: /Users/tom025/rails/factory-toys/spec/../tmp/ffactories/simple_factory.rb
4
4
 
5
5
  Test Instruction Queue and Processiung
6
6
  In order to ensure the Back Office Processes work as expected
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: factory_toys
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 2
10
- version: 0.2.2
9
+ - 3
10
+ version: 0.2.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - David Henry