fix_to_chix 0.0.2 → 0.0.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/History.txt +9 -0
- data/README.rdoc +5 -1
- data/Rakefile +4 -5
- data/bin/fixtochix +1 -1
- data/lib/fix_to_chix.rb +11 -3
- data/lib/fix_to_chix/controller.rb +3 -2
- data/lib/fix_to_chix/fixture_selector.rb +9 -8
- data/spec/controller_spec.rb +15 -5
- data/spec/fix_to_chix_spec.rb +14 -4
- data/spec/fixture_selector_spec.rb +31 -14
- data/tasks/rspec.rake +0 -12
- metadata +3 -3
data/History.txt
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
=== 0.0.3 2009-10-31
|
2
|
+
|
3
|
+
* Accepting arguments for matching names of fixtures to parse.
|
4
|
+
|
5
|
+
For example,
|
6
|
+
|
7
|
+
$ fixtochix -m user # => will only parse fixtures that match /user/
|
8
|
+
$ fixtochix -m posts # => will only parse fixtures that match /posts/
|
9
|
+
|
1
10
|
=== 0.0.2 2009-10-30
|
2
11
|
|
3
12
|
* Parsing fixtures with the default names (:one and :two) to factory names <model_name>_one and <model_name>_two so you don't end up with factories with the same name.
|
data/README.rdoc
CHANGED
@@ -6,10 +6,14 @@ http://github.com/caike/fix_to_chix
|
|
6
6
|
|
7
7
|
convert existing yaml fixtures to {factory_girl}[http://github.com/thoughtbot/factory_girl] factories
|
8
8
|
|
9
|
-
== FEATURES
|
9
|
+
== FEATURES:
|
10
10
|
|
11
11
|
It currently looks for yml files in your test and spec folders and translates them to factory_girl factory definitions written to test/factories.rb or spec/factories.rb
|
12
12
|
|
13
|
+
== PROBLEMS/TODO:
|
14
|
+
|
15
|
+
Check for namespaced modules, i.e. admin_posts.yml fixtures and Admin::Post model.
|
16
|
+
|
13
17
|
== SYNOPSIS:
|
14
18
|
|
15
19
|
Two simple steps to run fix_to_chix:
|
data/Rakefile
CHANGED
@@ -1,14 +1,13 @@
|
|
1
|
-
%w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
|
1
|
+
%w[rubygems rake rake/clean fileutils hoe newgem rubigen].each { |f| require f }
|
2
2
|
require File.dirname(__FILE__) + '/lib/fix_to_chix'
|
3
|
-
|
3
|
+
|
4
4
|
# Generate all the Rake tasks
|
5
5
|
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
6
|
-
$hoe = Hoe.
|
6
|
+
$hoe = Hoe.spec('fix_to_chix') do |p|
|
7
7
|
p.developer('Caike Souza', 'caikesouza@caikesouza.com')
|
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
|
-
p.
|
11
|
-
p.rubyforge_name = p.name # TODO this is default value
|
10
|
+
p.rubyforge_name = p.name
|
12
11
|
# p.extra_deps = [
|
13
12
|
# ['activesupport','>= 2.0.2'],
|
14
13
|
# ]
|
data/bin/fixtochix
CHANGED
data/lib/fix_to_chix.rb
CHANGED
@@ -7,7 +7,7 @@ require 'fix_to_chix/controller'
|
|
7
7
|
|
8
8
|
module FixToChix
|
9
9
|
|
10
|
-
VERSION = '0.0.
|
10
|
+
VERSION = '0.0.3'
|
11
11
|
|
12
12
|
APP_ROOT = "." # need to call fixtochix command from your app base
|
13
13
|
|
@@ -20,8 +20,16 @@ module FixToChix
|
|
20
20
|
SPEC_TARGET_FILE = "#{SPEC_TARGET}/factories.rb"
|
21
21
|
TEST_TARGET_FILE = "#{TEST_TARGET}/factories.rb"
|
22
22
|
|
23
|
-
def self.execute
|
24
|
-
FixToChix::Controller.parse_it_all!
|
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
|
25
33
|
end
|
26
34
|
|
27
35
|
end
|
@@ -4,8 +4,9 @@ require 'fix_to_chix/fixture_parser'
|
|
4
4
|
|
5
5
|
module FixToChix
|
6
6
|
class Controller
|
7
|
-
def self.parse_it_all!
|
8
|
-
|
7
|
+
def self.parse_it_all!(options={})
|
8
|
+
matching_option = options[:matching] ? { :matching => Regexp.new(options[:matching]) } : {}
|
9
|
+
selector = FixtureSelector.new(matching_option)
|
9
10
|
%w[spec test].each do |type|
|
10
11
|
selector.send("#{type}_fixtures").each do |fixture_file_name|
|
11
12
|
parser = FixtureParser.new(fixture_file_name)
|
@@ -1,22 +1,23 @@
|
|
1
1
|
module FixToChix
|
2
2
|
|
3
3
|
class FixtureSelector
|
4
|
-
|
4
|
+
|
5
5
|
attr_reader :test_fixtures_dir, :spec_fixtures_dir
|
6
6
|
|
7
7
|
def initialize(options={})
|
8
8
|
@test_fixtures_dir = options[:test_fixtures_dir] || TEST_FIXTURES
|
9
9
|
@spec_fixtures_dir = options[:spec_fixtures_dir] || SPEC_FIXTURES
|
10
|
+
@matching = options[:matching]
|
10
11
|
end
|
11
12
|
|
12
|
-
def spec_fixtures
|
13
|
+
def spec_fixtures
|
13
14
|
all_fixtures = fetch_fixtures.select {|f| f =~ /spec/ }
|
14
|
-
filter(all_fixtures
|
15
|
+
filter(all_fixtures)
|
15
16
|
end
|
16
17
|
|
17
|
-
def test_fixtures
|
18
|
+
def test_fixtures
|
18
19
|
all_fixtures = fetch_fixtures.select {|f| f =~ /test/ }
|
19
|
-
filter(all_fixtures
|
20
|
+
filter(all_fixtures)
|
20
21
|
end
|
21
22
|
|
22
23
|
private
|
@@ -26,13 +27,13 @@ module FixToChix
|
|
26
27
|
project_fixtures.concat(fetch_dir_files(self.spec_fixtures_dir))
|
27
28
|
project_fixtures
|
28
29
|
end
|
29
|
-
|
30
|
+
|
30
31
|
def fetch_dir_files(dir)
|
31
32
|
Dir[dir] unless Dir[dir].empty?
|
32
33
|
end
|
33
34
|
|
34
|
-
def filter(all_fixtures
|
35
|
-
return all_fixtures.select {|f| f =~
|
35
|
+
def filter(all_fixtures)
|
36
|
+
return all_fixtures.select {|f| f =~ @matching } if @matching
|
36
37
|
all_fixtures
|
37
38
|
end
|
38
39
|
|
data/spec/controller_spec.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
2
|
|
3
|
-
describe FixToChix::Controller do
|
4
|
-
|
5
|
-
it "
|
3
|
+
describe FixToChix::Controller do
|
4
|
+
|
5
|
+
it "parses spec fixtures" do
|
6
6
|
selector = mock('FixtureSelector', :spec_fixtures => ["spec_fix"], :test_fixtures => [])
|
7
7
|
FixToChix::FixtureSelector.stub!(:new).and_return(selector)
|
8
8
|
FixToChix::FixtureParser.should_receive(:new).with("spec_fix").and_return(mock('selector', :parse_fixture => "", :output_buffer => "buff"))
|
@@ -10,12 +10,22 @@ describe FixToChix::Controller do
|
|
10
10
|
FixToChix::Controller.parse_it_all!
|
11
11
|
end
|
12
12
|
|
13
|
-
it "
|
13
|
+
it "parses test fixtures" do
|
14
14
|
selector = mock('FixtureSelector', :spec_fixtures => [], :test_fixtures => ["test_fix"])
|
15
15
|
FixToChix::FixtureSelector.stub!(:new).and_return(selector)
|
16
16
|
FixToChix::FixtureParser.should_receive(:new).with("test_fix").and_return(mock('selector', :parse_fixture => "", :output_buffer => "buff"))
|
17
17
|
FixToChix::FactoryWriter.should_receive(:write).with("buff", FixToChix::TEST_TARGET_FILE)
|
18
18
|
FixToChix::Controller.parse_it_all!
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
|
+
it "accepts matching file options for selector" do
|
22
|
+
FixToChix::FixtureSelector.should_receive(:new).with(:matching => /anakin/).and_return(mock('Selector', :spec_fixtures => [], :test_fixtures => []))
|
23
|
+
FixToChix::Controller.parse_it_all!(:matching => "anakin")
|
24
|
+
end
|
25
|
+
|
26
|
+
it "receives empty hash if no arg" do
|
27
|
+
FixToChix::FixtureSelector.should_receive(:new).with({}).and_return(mock('Selector', :spec_fixtures => [], :test_fixtures => []))
|
28
|
+
FixToChix::Controller.parse_it_all!
|
29
|
+
end
|
30
|
+
|
21
31
|
end
|
data/spec/fix_to_chix_spec.rb
CHANGED
@@ -1,10 +1,20 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
2
|
|
3
3
|
describe FixToChix do
|
4
|
-
|
5
|
-
it "
|
4
|
+
|
5
|
+
it "parses it all" do
|
6
6
|
FixToChix::Controller.should_receive(:parse_it_all!)
|
7
7
|
FixToChix.execute
|
8
8
|
end
|
9
|
-
|
10
|
-
|
9
|
+
|
10
|
+
it "accepts arguments if given" do
|
11
|
+
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()
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -3,33 +3,50 @@ require File.dirname(__FILE__) + '/spec_helper.rb'
|
|
3
3
|
describe FixToChix::FixtureSelector do
|
4
4
|
|
5
5
|
describe "selecting fixtures" do
|
6
|
-
|
7
|
-
|
6
|
+
|
7
|
+
it "selects all spec fixtures by default" do
|
8
8
|
@selector = FixToChix::FixtureSelector.new
|
9
|
-
@selector.stub!(:
|
10
|
-
@selector.
|
11
|
-
@selector.stub!(:fetch_dir_files).with("test").and_return(["test/posts.yml"])
|
12
|
-
@selector.stub!(:fetch_dir_files).with("spec").and_return(["spec/fixtures/users.yml","spec/fixtures/user_items.yml"])
|
9
|
+
@selector.stub!(:fetch_fixtures).and_return(["spec/fixtures/users.yml","spec/fixtures/user_items.yml", "test/fixtures/posts.yml"])
|
10
|
+
@selector.spec_fixtures.should == ["spec/fixtures/users.yml","spec/fixtures/user_items.yml"]
|
13
11
|
end
|
14
12
|
|
15
|
-
it "selects all fixtures by default" do
|
16
|
-
@selector
|
17
|
-
@selector.
|
13
|
+
it "selects all test fixtures by default" do
|
14
|
+
@selector = FixToChix::FixtureSelector.new
|
15
|
+
@selector.stub!(:fetch_fixtures).and_return(["spec/fixtures/users.yml","spec/fixtures/user_items.yml", "test/fixtures/posts.yml"])
|
16
|
+
@selector.test_fixtures.should == ["test/fixtures/posts.yml"]
|
17
|
+
end
|
18
|
+
|
19
|
+
it "selects matching spec fixtures with regexp" do
|
20
|
+
@selector = FixToChix::FixtureSelector.new(:matching => /item/)
|
21
|
+
@selector.stub!(:fetch_fixtures).and_return(["spec/fixtures/users.yml","spec/fixtures/user_items.yml", "test/fixtures/posts.yml"])
|
22
|
+
@selector.spec_fixtures.should == ["spec/fixtures/user_items.yml"]
|
23
|
+
end
|
24
|
+
|
25
|
+
it "selected matching test fixtures with regexp" do
|
26
|
+
@selector = FixToChix::FixtureSelector.new(:matching => /space/)
|
27
|
+
@selector.stub!(:fetch_fixtures).and_return(["spec/fixtures/users.yml","spec/fixtures/user_items.yml", "test/fixtures/posts.yml", "test/fixtures/space_guns.yml"])
|
28
|
+
@selector.test_fixtures.should == ["test/fixtures/space_guns.yml"]
|
18
29
|
end
|
19
30
|
|
20
|
-
|
21
|
-
|
22
|
-
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "fetching fixtures" do
|
34
|
+
|
35
|
+
it "gets from default dirs" do
|
36
|
+
@selector = FixToChix::FixtureSelector.new
|
37
|
+
Dir.stub!(:[]).with(FixToChix::TEST_FIXTURES).and_return(["test/fixtures/space_guns.yml"])
|
38
|
+
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"])
|
23
40
|
end
|
24
41
|
|
25
42
|
end
|
26
|
-
|
43
|
+
|
27
44
|
describe "overriding default values" do
|
28
45
|
it "changes test fixture dir" do
|
29
46
|
@selector = FixToChix::FixtureSelector.new(:test_fixtures_dir => "/some/other")
|
30
47
|
@selector.test_fixtures_dir.should == "/some/other"
|
31
48
|
end
|
32
|
-
|
49
|
+
|
33
50
|
it "changes spec fixture dir" do
|
34
51
|
@selector = FixToChix::FixtureSelector.new(:spec_fixtures_dir => "/some/other")
|
35
52
|
@selector.spec_fixtures_dir.should == "/some/other"
|
data/tasks/rspec.rake
CHANGED
@@ -14,18 +14,6 @@ rescue LoadError
|
|
14
14
|
exit(0)
|
15
15
|
end
|
16
16
|
|
17
|
-
desc "Run the specs under spec/models"
|
18
|
-
Spec::Rake::SpecTask.new do |t|
|
19
|
-
t.spec_opts = ['--options', "spec/spec.opts"]
|
20
|
-
t.spec_files = FileList['spec/**/*_spec.rb']
|
21
|
-
end
|
22
|
-
|
23
|
-
namespace :fix_to_chix do
|
24
|
-
desc "Convert your fixtures to factory"
|
25
|
-
task :convert => :environment do
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
17
|
require 'spec/rake/spectask'
|
30
18
|
require "rcov/rcovtask"
|
31
19
|
|
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.
|
4
|
+
version: 0.0.3
|
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-
|
12
|
+
date: 2009-10-31 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -83,7 +83,7 @@ has_rdoc: true
|
|
83
83
|
homepage:
|
84
84
|
licenses: []
|
85
85
|
|
86
|
-
post_install_message:
|
86
|
+
post_install_message:
|
87
87
|
rdoc_options:
|
88
88
|
- --main
|
89
89
|
- README.txt
|