factory_toys 0.2.3 → 0.3.0

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/README.rdoc CHANGED
@@ -76,10 +76,29 @@ This is the Scenario that will be generated with the above options. This is shou
76
76
  The variable name used should be in the format:
77
77
  <identifier>_scenario
78
78
 
79
+ To Simplify the logic parts of the SCENARIO TEMNPLATE can be shared as follows
80
+
81
+ shared_scenario_part <<-DATA
82
+ @setup_#{dow}_settings
83
+ Given David is Better than Tom
84
+ When Tom is Great
85
+ DATA
86
+
87
+ my_first_scenario = <<- SCENARIO_TEMPLATE
88
+ << shared_scenario_part
89
+ Then Dave is Better
90
+ SCENARIO_TEMPLATE
91
+
92
+ my_second_scenario = <<- SCENARIO_TEMPLATE
93
+ << shared_scenario_part
94
+ And There is cake
95
+ Then Dave eats cake
96
+ SCENARIO_TEMPLATE
97
+
98
+ Note the use of '<< ' to insert the shared element
99
+
79
100
  == ToDo
80
101
 
81
- * Allow scenarios to be built from parts rather than just as a block of text
82
- - allow common parts of features to only be specified once and then shared basically
83
102
  * Add functionality to only rebuild the feature file if there has been a change most likely using fssm once I have a look and understand how it works..
84
103
  * Add other configuration options.. Not really sure what else is needed but am sure somthing will turn up
85
104
  * Fix the readme so it is not quite so much of a ramble.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.3
1
+ 0.3.0
data/factory_toys.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{factory_toys}
8
- s.version = "0.2.3"
8
+ s.version = "0.3.0"
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"]
12
- s.date = %q{2010-09-15}
12
+ s.date = %q{2010-09-20}
13
13
  s.description = %q{Simplify Feature Management}
14
14
  s.email = %q{dw_henry@yahoo.com.au}
15
15
  s.extra_rdoc_files = [
@@ -39,7 +39,7 @@ module FactoryToys
39
39
 
40
40
  def make_instance_variable(rows, row)
41
41
  if rows[row] =~ /^([\s]*)([^\s]+)([\s]*)=(.*)$/
42
- unless [':','"','"','@'].include?($2[0..0]) or
42
+ unless [':','"',"'",'@'].include?($2[0..0]) or
43
43
  ['>'].include?($4[0..0])
44
44
  rows[row] = "#{$1}@#{$2}#{$3}=#{$4}"
45
45
  end
@@ -47,12 +47,24 @@ module FactoryToys
47
47
  end
48
48
 
49
49
  def extract_element(rows, row, name, start_text)
50
- end_row = find_row(rows, row, start_text)
51
- elements[name.to_sym] = rows[row..end_row].join("\n")
50
+ end_row = find_closure_text(rows, row, start_text)
51
+ elements[name.to_sym] = self.element_string(rows[row..end_row])
52
52
  (row == 0 ? [] : rows[0..row-1]) + rows[end_row+1..-1]
53
53
  end
54
54
 
55
- def find_row(rows, row, start_text)
55
+ def element_string(element_rows)
56
+ element_rows.map! do |row|
57
+ if row =~ /^[\s]*<< ([^\s]+)[\s]*$/
58
+ raise UnknownInlineError, $1 unless elements[$1.to_sym]
59
+ elements[$1.to_sym].split("\n")[1..-2]
60
+ else
61
+ row
62
+ end
63
+ end
64
+ return element_rows.join("\n")
65
+ end
66
+
67
+ def find_closure_text(rows, row, start_text)
56
68
  rows[row..-1].each_with_index do |row_text, i|
57
69
  return row + i if row_text.strip == start_text
58
70
  end
data/lib/factory_toys.rb CHANGED
@@ -5,6 +5,7 @@ module FactoryToys
5
5
  class MissingForeachListError < StandardError; end
6
6
  class InternalForEachError < StandardError; end
7
7
  class MissingScenarioError < StandardError; end
8
+ class UnknownInlineError < StandardError; end
8
9
 
9
10
  class << self
10
11
  attr_accessor :features_directory, :source_directory
@@ -74,5 +74,68 @@ Data
74
74
  parser.elements
75
75
  end
76
76
  end
77
+
78
+ context 'with inline data sharing' do
79
+ it 'supports unline use of existing elements' do
80
+ string = <<-Data
81
+ string_one = <<-Str1
82
+ This is the test
83
+ Str1
84
+ string_two = <<-Str2
85
+ This is an inline test
86
+ << string_one
87
+ Str2
88
+ Data
89
+
90
+ parser = FactoryToys::Parser.new(string)
91
+
92
+ parser.elements[:base].should == ''
93
+ parser.elements[:string_one].should == "@string_one = <<-Str1\n" +
94
+ "This is the test\n" +
95
+ "Str1"
96
+
97
+ parser.elements[:string_two].should == "@string_two = <<-Str2\n" +
98
+ "This is an inline test\n" +
99
+ "This is the test\n" +
100
+ "Str2"
101
+ end
102
+
103
+ it 'supports inline use of multi-line existing elements' do
104
+ string = <<-Data
105
+ string_one = <<-Str1
106
+ This is the test
107
+ And so is this
108
+ Str1
109
+ string_two = <<-Str2
110
+ This is an inline test
111
+ << string_one
112
+ Str2
113
+ Data
114
+
115
+ parser = FactoryToys::Parser.new(string)
116
+
117
+ parser.elements[:base].should == ''
118
+
119
+ parser.elements[:string_two].should == "@string_two = <<-Str2\n" +
120
+ "This is an inline test\n" +
121
+ "This is the test\n" +
122
+ "And so is this\n" +
123
+ "Str2"
124
+ end
125
+
126
+ it 'when invalid inline element raises an error' do
127
+ string = <<-Data
128
+ string_one = <<-Str1
129
+ This is the test
130
+ Str1
131
+ string_two = <<-Str2
132
+ This is an inline test
133
+ << string_error
134
+ Str2
135
+ Data
136
+
137
+ lambda{ FactoryToys::Parser.new(string) }.should raise_error FactoryToys::UnknownInlineError, "string_error"
138
+ end
139
+ end
77
140
  end
78
141
  end
@@ -1,5 +1,5 @@
1
1
  # Auto Generated Features
2
- # Generated: Wed Sep 15 18:31:15 +0100 2010
2
+ # Generated: Mon Sep 20 10:55:43 +0100 2010
3
3
  # Source File: /Users/tom025/rails/factory-toys/spec/../tmp/ffactories/simple_factory.rb
4
4
 
5
5
  Test Instruction Queue and Processiung
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: 17
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 2
9
8
  - 3
10
- version: 0.2.3
9
+ - 0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - David Henry
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-09-15 00:00:00 +01:00
19
+ date: 2010-09-20 00:00:00 +01:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency