factory_toys 0.2.0 → 0.2.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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
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.0"
8
+ s.version = "0.2.1"
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"]
@@ -32,6 +32,7 @@ Gem::Specification.new do |s|
32
32
  "spec/factory_toys_spec.rb",
33
33
  "spec/spec.opts",
34
34
  "spec/spec_helper.rb",
35
+ "tmp/features/simple_factory.feature",
35
36
  "tmp/ffactories/simple_factory.rb"
36
37
  ]
37
38
  s.homepage = %q{http://github.com/tom025/factory-toys}
@@ -4,13 +4,16 @@ module FactoryToys
4
4
  attr_accessor :data
5
5
 
6
6
  def initialize(filename)
7
- @output = ''
8
7
  @filename = filename
9
- #build_output(filename)
8
+
9
+ @output = "# Auto Generated Features\n"
10
+ @output += "# Generated: #{Time.now.to_s}\n"
11
+ @output += "# Source File: #{@filename}\n\n"
12
+
10
13
  end
11
14
 
12
15
  def write
13
- filname = @filename.gsub(/.rb/,'.feature')
16
+ filename = File.basename(@filename, '.rb') + '.feature'
14
17
  File.open(FactoryToys.features_location + "/" + filename, 'w') do |f|
15
18
  f.puts self.output
16
19
  end
@@ -19,36 +22,35 @@ module FactoryToys
19
22
  def output
20
23
  eval(self.data[:base])
21
24
 
22
- self.build_feature(self.data[:feature])
25
+ self.add_feature(self.data[:feature])
23
26
 
24
27
  locals = self.send(:local_variables)
25
28
  scenarios = locals.find_all{|var| var =~ /_#{FactoryToys.scenarios}$/}
26
- scenarios.each do |scenario|
27
- options = get_options(scenario)
29
+ scenarios.each do |scenario_name|
30
+ feature = eval(scenario_name)
31
+ options = get_options(feature)
28
32
  options.each do |option|
29
- eval(self.get_option_string(scenario, option))
30
- option =~ /^(.+)_#{FactoryToys.scenarios}$/
33
+ eval(self.option_string(feature, option))
34
+ scenario_name =~ /^(.+)_#{FactoryToys.scenarios}$/
31
35
  identifier = $1
32
- scenario = "#{identifer}_#{FactoryToys.scenario}"
33
- raise MissingScenarioError, scenario unless scenarios[scenario]
34
- eval(scenarios[scenario])
35
- output += scenario + "\n\n"
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"
36
40
  end
37
41
  end
42
+ @output
38
43
  end
39
44
 
40
45
  def add_feature(feature)
41
46
  raise FactoryToys::MissingFeatureDefinitionError if feature.blank?
42
- output += feature
43
- end
44
-
45
- def add_scenario(scenario, options)
46
-
47
+ eval(feature)
48
+ @output += eval('feature') + "\n\n"
47
49
  end
48
50
 
49
51
  def data
50
52
  return @data if @data
51
- file = File.open(FactoryToys.source_location + "/" + @filename, 'r')
53
+ file = File.open(@filename, 'r')
52
54
  @data = Parser.new(file.read).elements
53
55
  end
54
56
 
@@ -56,7 +58,22 @@ module FactoryToys
56
58
  return '' unless scenario[:foreach]
57
59
  foreach = get_option_types(scenario[:foreach], false)
58
60
  raise InternalForEachError unless foreach.size == option.size
59
- foreach.map(&:to_s).join(', ') + ' = ' + option.map(&:to_s).join(', ')
61
+ foreach.map(&:to_s).join(', ') + ' = ' + option.map{|o| self.write_value(o)}.join(', ')
62
+ end
63
+
64
+ def write_value(o)
65
+ case o
66
+ when Symbol
67
+ return ":#{o}"
68
+ when String
69
+ return "'#{o}'"
70
+ when Numeric
71
+ return o.to_s
72
+ when Array
73
+ "[#{o.map{|v| self.write_value(v).join(',')}}]"
74
+ when Hash
75
+ "{#{o.map{|k,v| self.write_value(k) + ' => ' + self.write_value(v)}.join(', ')}}"
76
+ end
60
77
  end
61
78
 
62
79
  def get_options(scenario)
@@ -22,7 +22,7 @@ module FactoryToys
22
22
  end
23
23
 
24
24
  def split_by_row(data)
25
- data.split("\n").map(&:strip).find_all{|str| !str.blank?}
25
+ data.split("\n")
26
26
  end
27
27
 
28
28
  def process_element(rows, row)
data/lib/factory_toys.rb CHANGED
@@ -1,3 +1,4 @@
1
+
1
2
  module FactoryToys
2
3
  class MissingEnvironmentError < StandardError; end
3
4
  class CloseTagNotFoundError < StandardError; end
@@ -28,7 +29,7 @@ module FactoryToys
28
29
 
29
30
  protected
30
31
  def source_files
31
- Dir.glob(self.source_location, '*')
32
+ Dir.glob(self.source_location + '/*.rb')
32
33
  rescue Errno::ENOENT => e
33
34
  return "Source Directory Does not exist: #{self.source_directory}"
34
35
  end
@@ -1,11 +1,5 @@
1
1
  require 'spec_helper'
2
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
3
 
10
4
  describe FactoryToys::FFactory do
11
5
  before do
@@ -36,17 +36,17 @@ describe FactoryToys::Parser do
36
36
  run_factory[:base].should == "test='testing'\ngreeting='Hello Again'"
37
37
  end
38
38
 
39
- it "removes blank lines" do
39
+ it "does not remove blank lines" do
40
40
  run_factory("\n\ndate='Dont look at me??'")[:base].should ==
41
- "test='testing'\ngreeting='Hello Again'\ndate='Dont look at me??'"
41
+ "test='testing'\ngreeting='Hello Again'\n\n\ndate='Dont look at me??'"
42
42
  end
43
43
 
44
44
  it "when named variables only" do
45
45
  string = <<-Data
46
- other_string = <<-TestData
47
- value=test
48
- TestData
49
- Data
46
+ other_string = <<-TestData
47
+ value=test
48
+ TestData
49
+ Data
50
50
  parser = FactoryToys::Parser.new(string)
51
51
 
52
52
  parser.elements[:base].should == ''
@@ -57,12 +57,12 @@ describe FactoryToys::Parser do
57
57
 
58
58
  def run_factory(additional_text='')
59
59
  string = <<-Data
60
- test='testing'
61
- other_string = <<-TestData
62
- value=test
63
- TestData
64
- greeting='Hello Again'
65
- Data
60
+ test='testing'
61
+ other_string = <<-TestData
62
+ value=test
63
+ TestData
64
+ greeting='Hello Again'
65
+ Data
66
66
  parser = FactoryToys::Parser.new(string + additional_text)
67
67
  parser.elements
68
68
  end
@@ -2,7 +2,7 @@ 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, File.dirname(__FILE__) + '/../tmp/empty') unless Object.const_defined?(:RAILS_ROOT)
5
+ Object.const_set(:RAILS_ROOT, Dir.pwd + '/' + File.dirname(__FILE__) + '/../tmp/empty') unless Object.const_defined?(:RAILS_ROOT)
6
6
  end
7
7
 
8
8
  context '#update_features' do
@@ -28,9 +28,19 @@ describe "FactoryToys" do
28
28
  end
29
29
 
30
30
  it 'calls Process FFactory for each file' do
31
+ factory = mock(:fact1, :write => true)
31
32
  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)
33
+ FactoryToys::FFactory.should_receive(:new).with('file1').and_return(factory)
34
+ FactoryToys::FFactory.should_receive(:new).with('file2').and_return(factory)
35
+ FactoryToys.update_features
36
+ end
37
+
38
+ it 'calls write for each file' do
39
+ factory = mock(:fact1)
40
+ FactoryToys.stub!(:source_files).and_return(['file1', 'file2'])
41
+ FactoryToys::FFactory.stub!(:new).and_return(factory)
42
+ factory.should_receive(:write).and_return(true)
43
+ factory.should_receive(:write).and_return(true)
34
44
  FactoryToys.update_features
35
45
  end
36
46
  end
@@ -44,6 +54,15 @@ describe "FactoryToys" do
44
54
  FactoryToys.scenarios.should == 'feature'
45
55
  end
46
56
  end
57
+
58
+ context 'actually produce a file' do
59
+ it 'creates a file' do
60
+ FileUtils.rm_r(FactoryToys.features_location + '/*', :force => true)
61
+ Object.send(:remove_const, :RAILS_ROOT)
62
+ Object.const_set(:RAILS_ROOT, Dir.pwd + '/' + File.dirname(__FILE__) + '/../tmp')
63
+ FactoryToys.update_features
64
+ end
65
+ end
47
66
  end
48
67
 
49
68
  end
data/spec/spec_helper.rb CHANGED
@@ -8,3 +8,14 @@ require 'spec/autorun'
8
8
  Spec::Runner.configure do |config|
9
9
 
10
10
  end
11
+
12
+ SETTLEMENT_METHODS = [DCC_DCC = {:buy => 'dcc from dcc', :to => 'dcc to dcc'},
13
+ REG_REG = {:buy => 'reg from reg', :to => 'reg to reg'}
14
+ ]
15
+
16
+ #implemented here to get tests to pass as in Rails Environment and not ruby core??
17
+ class String
18
+ def blank?
19
+ self.nil? or self == ''
20
+ end
21
+ end
@@ -0,0 +1,70 @@
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
4
+
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
+
10
+
11
+ @selenium @buy_trade_ticket_requirements @login_as_middle_office
12
+ Ing Trade Ticket Instructions - buy dcc from dcc
13
+ Given I am on the Instructions Screen
14
+ When I click the trade row
15
+ Then I should see "Instruction Details"
16
+ When I set Settlement Method to "dcc from dcc" for trade
17
+ Then I should see Settlement Method "dcc from dcc" for trade
18
+ When I follow "Broker Confirm"
19
+ Then I should see "Instruct Trade"
20
+ And I should see trade row
21
+ When I follow "Instruct Trade" with confirmation
22
+ Then I should not see trade row
23
+ And Instruction File exists on Hard Drive
24
+
25
+
26
+ @selenium @buy_trade_ticket_requirements @login_as_middle_office
27
+ Ing Trade Ticket Instructions - buy reg from reg
28
+ Given I am on the Instructions Screen
29
+ When I click the trade row
30
+ Then I should see "Instruction Details"
31
+ When I set Settlement Method to "reg from reg" for trade
32
+ Then I should see Settlement Method "reg from reg" for trade
33
+ When I follow "Broker Confirm"
34
+ Then I should see "Instruct Trade"
35
+ And I should see trade row
36
+ When I follow "Instruct Trade" with confirmation
37
+ Then I should not see trade row
38
+ And Instruction File exists on Hard Drive
39
+
40
+
41
+ @selenium @sell_trade_ticket_requirements @login_as_middle_office
42
+ Ing Trade Ticket Instructions - sell
43
+ Given I am on the Instructions Screen
44
+ When I click the trade row
45
+ Then I should see "Instruction Details"
46
+ When I set Settlement Method to "" for trade
47
+ Then I should see Settlement Method "" for trade
48
+ When I follow "Broker Confirm"
49
+ Then I should see "Instruct Trade"
50
+ And I should see trade row
51
+ When I follow "Instruct Trade" with confirmation
52
+ Then I should not see trade row
53
+ And Instruction File exists on Hard Drive
54
+
55
+
56
+ @selenium @sell_trade_ticket_requirements @login_as_middle_office
57
+ Ing Trade Ticket Instructions - sell
58
+ Given I am on the Instructions Screen
59
+ When I click the trade row
60
+ Then I should see "Instruction Details"
61
+ When I set Settlement Method to "" for trade
62
+ Then I should see Settlement Method "" for trade
63
+ When I follow "Broker Confirm"
64
+ Then I should see "Instruct Trade"
65
+ And I should see trade row
66
+ When I follow "Instruct Trade" with confirmation
67
+ Then I should not see trade row
68
+ And Instruction File exists on Hard Drive
69
+
70
+
@@ -1,6 +1,3 @@
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
1
  feature = <<-Data
5
2
  Test Instruction Queue and Processiung
6
3
  In order to ensure the Back Office Processes work as expected
@@ -10,7 +7,7 @@ Data
10
7
 
11
8
  ing_feature = {
12
9
  :foreach => [:direction, :settlement_method],
13
- :direction => ['buy', 'sell'],
10
+ :direction => [:buy, :sell],
14
11
  :settlement_method => SETTLEMENT_METHODS
15
12
  }
16
13
 
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: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 0
10
- version: 0.2.0
9
+ - 1
10
+ version: 0.2.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - David Henry
@@ -60,6 +60,7 @@ files:
60
60
  - spec/factory_toys_spec.rb
61
61
  - spec/spec.opts
62
62
  - spec/spec_helper.rb
63
+ - tmp/features/simple_factory.feature
63
64
  - tmp/ffactories/simple_factory.rb
64
65
  has_rdoc: true
65
66
  homepage: http://github.com/tom025/factory-toys