fix_to_chix 0.0.3 → 0.0.5

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/Rakefile CHANGED
@@ -8,9 +8,6 @@ $hoe = Hoe.spec('fix_to_chix') do |p|
8
8
  p.summary = 'convert existing yaml fixtures to factory_girl factories'
9
9
  p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
10
10
  p.rubyforge_name = p.name
11
- # p.extra_deps = [
12
- # ['activesupport','>= 2.0.2'],
13
- # ]
14
11
  p.extra_dev_deps = [
15
12
  ['newgem', ">= #{::Newgem::VERSION}"], ['activesupport']
16
13
  ]
@@ -1,4 +1,18 @@
1
1
  #!/usr/bin/env ruby
2
+ begin
3
+ require 'fix_to_chix'
4
+ rescue LoadError
5
+ require File.dirname(__FILE__) + '/../lib/fix_to_chix'
6
+ end
2
7
 
3
- require 'fix_to_chix'
4
- FixToChix.execute(ARGV)
8
+ options = {}
9
+
10
+ OptionParser.new do |opt|
11
+ opt.banner = "Usage: cd /your/app/base/dir; fixtochix [OPTIONS]"
12
+ opt.on("-m", "--match FILES", "Match file pattern") do |m|
13
+ options[:matching] = m
14
+ end
15
+ opt.parse!
16
+ end
17
+
18
+ FixToChix.execute(options)
@@ -4,10 +4,11 @@ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname
4
4
  require 'rubygems'
5
5
  require 'activesupport'
6
6
  require 'fix_to_chix/controller'
7
+ require 'optparse'
7
8
 
8
9
  module FixToChix
9
10
 
10
- VERSION = '0.0.3'
11
+ VERSION = '0.0.5'
11
12
 
12
13
  APP_ROOT = "." # need to call fixtochix command from your app base
13
14
 
@@ -20,16 +21,8 @@ module FixToChix
20
21
  SPEC_TARGET_FILE = "#{SPEC_TARGET}/factories.rb"
21
22
  TEST_TARGET_FILE = "#{TEST_TARGET}/factories.rb"
22
23
 
23
- def self.execute(args=nil)
24
- FixToChix::Controller.parse_it_all!(parse_arguments(args))
25
- end
26
-
27
- def self.parse_arguments(args)
28
- if args && args.index("-m")
29
- { :matching => (args[args.index("-m") + 1]) }
30
- else
31
- {}
32
- end
24
+ def self.execute(options)
25
+ FixToChix::Controller.parse_it_all!(options)
33
26
  end
34
27
 
35
28
  end
@@ -4,16 +4,27 @@ require 'fix_to_chix/fixture_parser'
4
4
 
5
5
  module FixToChix
6
6
  class Controller
7
- def self.parse_it_all!(options={})
8
- matching_option = options[:matching] ? { :matching => Regexp.new(options[:matching]) } : {}
9
- selector = FixtureSelector.new(matching_option)
10
- %w[spec test].each do |type|
11
- selector.send("#{type}_fixtures").each do |fixture_file_name|
12
- parser = FixtureParser.new(fixture_file_name)
13
- parser.parse_fixture
14
- FactoryWriter.write(parser.output_buffer, FixToChix.class_eval("#{type.upcase}_TARGET_FILE"))
7
+
8
+ class << self
9
+
10
+ def parse_it_all!(options)
11
+ matching_options = parse_matching_options(options)
12
+ selector = FixtureSelector.new(matching_options)
13
+ %w[spec test].each do |type|
14
+ selector.send("#{type}_fixtures").each do |fixture_file_name|
15
+ parser = FixtureParser.new(fixture_file_name)
16
+ parser.parse_fixture
17
+ FactoryWriter.write(parser.output_buffer, FixToChix.class_eval("#{type.upcase}_TARGET_FILE"))
18
+ end
15
19
  end
16
20
  end
21
+
22
+ def parse_matching_options(options)
23
+ return {} unless options[:matching]
24
+ { :matching => Regexp.new(options[:matching]) }
25
+ end
26
+
17
27
  end
28
+
18
29
  end
19
30
  end
@@ -29,7 +29,11 @@ module FixToChix
29
29
  end
30
30
 
31
31
  def fetch_dir_files(dir)
32
- Dir[dir] unless Dir[dir].empty?
32
+ if Dir[dir].empty?
33
+ []
34
+ else
35
+ Dir[dir]
36
+ end
33
37
  end
34
38
 
35
39
  def filter(all_fixtures)
@@ -1,31 +1,75 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper.rb'
2
2
 
3
3
  describe FixToChix::Controller do
4
-
5
- it "parses spec fixtures" do
6
- selector = mock('FixtureSelector', :spec_fixtures => ["spec_fix"], :test_fixtures => [])
7
- FixToChix::FixtureSelector.stub!(:new).and_return(selector)
8
- FixToChix::FixtureParser.should_receive(:new).with("spec_fix").and_return(mock('selector', :parse_fixture => "", :output_buffer => "buff"))
9
- FixToChix::FactoryWriter.should_receive(:write).with("buff", FixToChix::SPEC_TARGET_FILE)
10
- FixToChix::Controller.parse_it_all!
4
+
5
+ describe "parses spec fixtures" do
6
+
7
+ it "parses spec fixtures" do
8
+ selector = mock('FixtureSelector', :spec_fixtures => ["spec_fix"], :test_fixtures => [])
9
+ FixToChix::FixtureSelector.stub!(:new).and_return(selector)
10
+ FixToChix::FixtureParser.should_receive(:new).with("spec_fix").and_return(mock('Parser', :parse_fixture => "", :output_buffer => "buff"))
11
+ FixToChix::FactoryWriter.stub!(:write).with("buff", FixToChix::SPEC_TARGET_FILE)
12
+ FixToChix::Controller.parse_it_all!({})
13
+ end
14
+
15
+ it "writes to buffer" do
16
+ selector = mock('FixtureSelector', :spec_fixtures => ["spec_fix"], :test_fixtures => [])
17
+ FixToChix::FixtureSelector.stub!(:new).and_return(selector)
18
+ FixToChix::FixtureParser.stub!(:new).with("spec_fix").and_return(mock('Parser', :parse_fixture => "", :output_buffer => "buff"))
19
+ FixToChix::FactoryWriter.should_receive(:write).with("buff", FixToChix::SPEC_TARGET_FILE)
20
+ FixToChix::Controller.parse_it_all!({})
21
+ end
22
+
11
23
  end
12
-
13
- it "parses test fixtures" do
14
- selector = mock('FixtureSelector', :spec_fixtures => [], :test_fixtures => ["test_fix"])
15
- FixToChix::FixtureSelector.stub!(:new).and_return(selector)
16
- FixToChix::FixtureParser.should_receive(:new).with("test_fix").and_return(mock('selector', :parse_fixture => "", :output_buffer => "buff"))
17
- FixToChix::FactoryWriter.should_receive(:write).with("buff", FixToChix::TEST_TARGET_FILE)
18
- FixToChix::Controller.parse_it_all!
24
+
25
+ describe "parses test fixtures" do
26
+
27
+ it "parses test fixtures" do
28
+ selector = mock('FixtureSelector', :spec_fixtures => [], :test_fixtures => ["test_fix"])
29
+ FixToChix::FixtureSelector.stub!(:new).and_return(selector)
30
+ FixToChix::FixtureParser.should_receive(:new).with("test_fix").and_return(mock('Parser', :parse_fixture => "", :output_buffer => "buff"))
31
+ FixToChix::FactoryWriter.stub!(:write).with("buff", FixToChix::TEST_TARGET_FILE)
32
+ FixToChix::Controller.parse_it_all!({})
33
+ end
34
+
35
+ it "writes to buffer" do
36
+ selector = mock('FixtureSelector', :spec_fixtures => [], :test_fixtures => ["test_fix"])
37
+ FixToChix::FixtureSelector.stub!(:new).and_return(selector)
38
+ FixToChix::FixtureParser.stub!(:new).with("test_fix").and_return(mock('Parser', :parse_fixture => "", :output_buffer => "buff"))
39
+ FixToChix::FactoryWriter.should_receive(:write).with("buff", FixToChix::TEST_TARGET_FILE)
40
+ FixToChix::Controller.parse_it_all!({})
41
+ end
42
+
19
43
  end
20
44
 
21
- it "accepts matching file options for selector" do
45
+ it "accepts matching one file options for selector" do
22
46
  FixToChix::FixtureSelector.should_receive(:new).with(:matching => /anakin/).and_return(mock('Selector', :spec_fixtures => [], :test_fixtures => []))
23
47
  FixToChix::Controller.parse_it_all!(:matching => "anakin")
24
48
  end
49
+
50
+ it "accepts matching many files options for selector" do
51
+ FixToChix::FixtureSelector.should_receive(:new).with(:matching => /anakin|yoda/).and_return(mock('Selector', :spec_fixtures => [], :test_fixtures => []))
52
+ FixToChix::Controller.parse_it_all!(:matching => "anakin|yoda")
53
+ end
25
54
 
26
- it "receives empty hash if no arg" do
55
+ it "receives empty hash if no arguments for matching" do
27
56
  FixToChix::FixtureSelector.should_receive(:new).with({}).and_return(mock('Selector', :spec_fixtures => [], :test_fixtures => []))
28
- FixToChix::Controller.parse_it_all!
57
+ FixToChix::Controller.parse_it_all!({:bla => "bla"})
29
58
  end
30
-
59
+
60
+ it "parses hash from matching arguments if given one" do
61
+ matching_options = FixToChix::Controller.parse_matching_options(:matching => "blablabla")
62
+ matching_options.should == { :matching => /blablabla/ }
63
+ end
64
+
65
+ it "parses hash from matching arguments if given two" do
66
+ matching_options = FixToChix::Controller.parse_matching_options(:matching => "blablabla|ble")
67
+ matching_options.should == { :matching => /blablabla|ble/ }
68
+ end
69
+
70
+ it "parses empty hash from matching arguments if none given" do
71
+ matching_options = FixToChix::Controller.parse_matching_options({})
72
+ matching_options.should == {}
73
+ end
74
+
31
75
  end
@@ -1,20 +1,14 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper.rb'
2
2
 
3
3
  describe FixToChix do
4
-
5
- it "parses it all" do
6
- FixToChix::Controller.should_receive(:parse_it_all!)
7
- FixToChix.execute
4
+
5
+ it "prints usage if no arguments passed" do
6
+ lambda{ FixToChix.execute }.should raise_error(ArgumentError)
8
7
  end
9
8
 
10
- it "accepts arguments if given" do
9
+ it "accepts matching arguments" do
11
10
  FixToChix::Controller.should_receive(:parse_it_all!).with(:matching => "chewbacca")
12
- FixToChix.execute(["-m", "chewbacca"])
13
- end
14
-
15
- it "accepts passes empty hash if no argument" do
16
- FixToChix::Controller.should_receive(:parse_it_all!).with({})
17
- FixToChix.execute()
11
+ FixToChix.execute(:matching => "chewbacca")
18
12
  end
19
13
 
20
14
  end
@@ -31,12 +31,21 @@ describe FixToChix::FixtureSelector do
31
31
  end
32
32
 
33
33
  describe "fetching fixtures" do
34
-
35
- it "gets from default dirs" do
34
+
35
+ before do
36
36
  @selector = FixToChix::FixtureSelector.new
37
+ end
38
+
39
+ it "gets from default test dir" do
37
40
  Dir.stub!(:[]).with(FixToChix::TEST_FIXTURES).and_return(["test/fixtures/space_guns.yml"])
41
+ Dir.stub!(:[]).with(FixToChix::SPEC_FIXTURES).and_return([])
42
+ @selector.send(:fetch_fixtures).to_set.should == Set.new(["test/fixtures/space_guns.yml"])
43
+ end
44
+
45
+ it "gets from default spec dif" do
46
+ Dir.stub!(:[]).with(FixToChix::TEST_FIXTURES).and_return([])
38
47
  Dir.stub!(:[]).with(FixToChix::SPEC_FIXTURES).and_return(["spec/fixtures/user_items.yml"])
39
- @selector.send(:fetch_fixtures).to_set.should == Set.new(["spec/fixtures/user_items.yml","test/fixtures/space_guns.yml"])
48
+ @selector.send(:fetch_fixtures).to_set.should == Set.new(["spec/fixtures/user_items.yml"])
40
49
  end
41
50
 
42
51
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fix_to_chix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Caike Souza
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-31 00:00:00 -04:00
12
+ date: 2009-12-12 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency