taza 0.8.3 → 0.8.4

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.
@@ -1,3 +1,10 @@
1
+ === 0.8.4
2
+
3
+ * Added one to many relationship in fixtures
4
+ * Added Templating of fixtures
5
+ * Added Site Secific fixtures
6
+ * Spec Rake Tasks are now generated Recursively
7
+
1
8
  === 0.8.2 / 2009-01-11
2
9
 
3
10
  * Added Partials
@@ -1,4 +1,4 @@
1
1
  ---
2
- patch: 3
3
- major: 0
4
- minor: 8
2
+ :major: 0
3
+ :minor: 8
4
+ :patch: 4
@@ -1,4 +1,5 @@
1
1
  module Taza
2
+
2
3
  class Entity
3
4
  #Creates a entity, pass in a hash to be methodized and the fixture to look up other fixtures (not entirely happy with this abstraction)
4
5
  def initialize(hash,fixture)
@@ -18,7 +19,9 @@ module Taza
18
19
 
19
20
  #This method will lookup another fixture if a pluralized fixture exists otherwise return the value in the hash
20
21
  def get_value_for_entry(key) # :nodoc:
21
- if @fixture.pluralized_fixture_exists?(key)
22
+ if @fixture.fixture_exists?(key)
23
+ @fixture.specific_fixture_entities(key.to_sym, @hash[key])
24
+ elsif @fixture.pluralized_fixture_exists?(key)
22
25
  @fixture.get_fixture_entity(key.pluralize_to_sym,@hash[key])
23
26
  else
24
27
  @hash[key]
@@ -1,3 +1,6 @@
1
+ require 'find'
2
+ require "erb"
3
+
1
4
  module Taza
2
5
  class Fixture # :nodoc:
3
6
 
@@ -5,10 +8,13 @@ module Taza
5
8
  @fixtures = {}
6
9
  end
7
10
 
8
- def load_all # :nodoc:
9
- Dir.glob(fixtures_pattern) do |file|
11
+ def load_all(fixtures_pattern) # :nodoc:
12
+ index_of_fixtures = fixtures_pattern.index("fixtures")
13
+ truncated_pattern = fixtures_pattern[index_of_fixtures..-1]
14
+ Dir.glob(File.join(base_path,truncated_pattern)) do |file|
15
+ templatized_fixture=ERB.new(File.read(file))
10
16
  entitized_fixture = {}
11
- YAML.load_file(file).each do |key, value|
17
+ YAML.load(templatized_fixture.result()).each do |key, value|
12
18
  entitized_fixture[key] = value.convert_hash_keys_to_methods(self)
13
19
  end
14
20
  @fixtures[File.basename(file,'.yml').to_sym] = entitized_fixture
@@ -18,22 +24,31 @@ module Taza
18
24
  def fixture_names # :nodoc:
19
25
  @fixtures.keys
20
26
  end
27
+
28
+ def get_fixture(fixture_file_key)
29
+ @fixtures[fixture_file_key]
30
+ end
21
31
 
22
32
  def get_fixture_entity(fixture_file_key,entity_key) # :nodoc:
23
33
  @fixtures[fixture_file_key][entity_key]
24
34
  end
25
35
 
26
36
  def pluralized_fixture_exists?(singularized_fixture_name) # :nodoc:
27
- fixture_names.include?(singularized_fixture_name.pluralize_to_sym)
37
+ fixture_exists?(singularized_fixture_name.pluralize_to_sym)
28
38
  end
29
-
30
- def fixtures_pattern # :nodoc:
31
- File.join(base_path, 'fixtures','*.yml')
39
+
40
+ def specific_fixture_entities(fixture_key, select_array)
41
+ cloned_fixture = @fixtures[fixture_key].clone
42
+ cloned_fixture.delete_if {|key , value| !select_array.include?(key)}
32
43
  end
33
44
 
34
- def base_path # :nodoc:
35
- File.join('.','spec')
45
+ def fixture_exists?(fixture_name)
46
+ fixture_names.include?(fixture_name.to_sym)
36
47
  end
48
+
49
+ def base_path # :nodoc:
50
+ File.join('.','spec')
51
+ end
37
52
  end
38
53
 
39
54
  # The module that will mixin methods based on the fixture files in your 'spec/fixtures'
@@ -49,18 +64,25 @@ module Taza
49
64
  # jane_smith:
50
65
  # first_name: jane
51
66
  # last_name: smith
52
- module Fixtures
53
- def Fixtures.included(other_module) # :nodoc:
54
- fixture = Fixture.new
55
- fixture.load_all
56
- fixture.fixture_names.each do |fixture_name|
57
- self.class_eval do
58
- define_method(fixture_name) do |entity_key|
59
- fixture.get_fixture_entity(fixture_name,entity_key.to_s)
67
+ dirs = Dir.glob(File.join(Fixture.new.base_path,"**","**")).select {|d| File.directory?(d) }
68
+ dirs[0,0] = File.join(Fixture.new.base_path,"fixtures")
69
+ dirs.each do |mod|
70
+ base_module = mod == dirs[0] ? "" : "Fixtures::"
71
+ self.class_eval <<-EOS
72
+ module #{base_module}#{mod.split('/')[-1].camelize}
73
+ def self.included(other_module)
74
+ fixture = Fixture.new
75
+ fixture.load_all(File.join("#{mod}","*.yml"))
76
+ fixture.fixture_names.each do |fixture_name|
77
+ self.class_eval do
78
+ define_method(fixture_name) do |entity_key|
79
+ fixture.get_fixture_entity(fixture_name,entity_key.to_s)
80
+ end
81
+ end
60
82
  end
61
83
  end
62
84
  end
63
- end
64
- end
85
+ EOS
86
+ end
87
+ end
65
88
 
66
- end
@@ -1,6 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'rake'
3
- require 'taglob/rake/tasks'
3
+ require 'taglob'
4
4
  require 'spec/rake/spectask'
5
5
 
6
6
  def tags
@@ -26,27 +26,22 @@ module Taza
26
26
 
27
27
  def define
28
28
  namespace :spec do
29
- desc "Run all functional specs"
30
- define_spec_task(:functional,'spec/functional/**/*_spec.rb')
31
- desc "Run all integration specs"
32
- define_spec_task(:integration,'spec/integration/**/*_spec.rb')
33
-
34
- namespace :functional do
35
- Dir.glob('./spec/functional/*/').each do |dir|
36
- site_name = File.basename(dir)
37
- desc "Run all functional specs for #{site_name}"
38
- define_spec_task(site_name,"#{dir}**/*_spec.rb")
39
-
40
- namespace site_name do
41
- Dir.glob("./spec/functional/#{site_name}/*_spec.rb").each do |page_spec_file|
42
- page_name = File.basename(page_spec_file,'_spec.rb')
43
- define_spec_task(page_name,page_spec_file)
44
- end
45
- end
46
-
47
- end
29
+ Dir.glob('./spec/*/').each do |dir|
30
+ recurse_to_create_rake_tasks(dir)
31
+ end
32
+ end
33
+ end
34
+ def recurse_to_create_rake_tasks(dir)
35
+ basename = File.basename(dir)
36
+ define_spec_task(basename,File.join(dir,"**","*_spec.rb"))
37
+ namespace basename do
38
+ Dir.glob(File.join(dir,"*_spec.rb")).each do |spec_file|
39
+ spec_name = File.basename(spec_file,'_spec.rb')
40
+ define_spec_task(spec_name,spec_file)
41
+ end
42
+ Dir.glob(File.join(dir,"*/")).each do |sub_dir|
43
+ recurse_to_create_rake_tasks(sub_dir)
48
44
  end
49
-
50
45
  end
51
46
  end
52
47
  end
@@ -6,7 +6,7 @@ describe Taza::Fixture do
6
6
  it "should be able to load entries from fixtures" do
7
7
  Taza::Fixture.any_instance.stubs(:base_path).returns('./spec/sandbox')
8
8
  fixture = Taza::Fixture.new
9
- fixture.load_all
9
+ fixture.load_all(File.join('fixtures','*.yml'))
10
10
  example = fixture.get_fixture_entity(:examples,'first_example')
11
11
  example.name.should eql("first")
12
12
  example.price.should eql(1)
@@ -19,16 +19,41 @@ describe Taza::Fixture do
19
19
  it "should know if a pluralized fixture of that name exists" do
20
20
  Taza::Fixture.any_instance.stubs(:base_path).returns('./spec/sandbox')
21
21
  fixture = Taza::Fixture.new
22
- fixture.load_all
22
+ fixture.load_all(File.join('fixtures','*.yml'))
23
23
  fixture.pluralized_fixture_exists?('example').should be_true
24
- fixture.pluralized_fixture_exists?('foo').should be_false
24
+ fixture.pluralized_fixture_exists?('boo').should be_false
25
25
  end
26
26
 
27
- it "should be able to get all fixtures loaded" do
27
+ it "should be able to get all fixtures loaded excluding sub-folder fixtures" do
28
28
  Taza::Fixture.any_instance.stubs(:base_path).returns('./spec/sandbox')
29
29
  fixture = Taza::Fixture.new
30
- fixture.load_all
31
- fixture.fixture_names.should be_equivalent([:examples,:users])
30
+ fixture.load_all(File.join('fixtures','*.yml'))
31
+ fixture.fixture_names.should be_equivalent([:examples,:users,:foos])
32
+ end
33
+
34
+ it "should be able to get all fixtures loaded including sub-folder fixtures" do
35
+ Taza::Fixture.any_instance.stubs(:base_path).returns('./spec/sandbox')
36
+ fixture = Taza::Fixture.new
37
+ fixture.load_all(File.join('fixtures','**','*.yml'))
38
+ fixture.fixture_names.should be_equivalent([:examples,:users,:foos,:bars])
39
+ end
40
+
41
+ it "should be able to get specific fixture entities" do
42
+ Taza::Fixture.any_instance.stubs(:base_path).returns('./spec/sandbox')
43
+ fixture = Taza::Fixture.new
44
+ fixture.load_all(File.join('fixtures','*.yml'))
45
+ examples = fixture.specific_fixture_entities(:examples, ['third_example'])
46
+ examples.length.should eql(1)
47
+ examples['third_example'].name.should eql('third')
48
+ end
49
+
50
+ it "should not modified the fixtures when you get specific entities off a fixture" do
51
+ Taza::Fixture.any_instance.stubs(:base_path).returns('./spec/sandbox')
52
+ fixture = Taza::Fixture.new
53
+ fixture.load_all(File.join('fixtures','*.yml'))
54
+ previous_count = fixture.get_fixture(:examples).length
55
+ examples = fixture.specific_fixture_entities(:examples, ['third_example'])
56
+ fixture.get_fixture(:examples).length.should eql(previous_count)
32
57
  end
33
58
 
34
- end
59
+ end
@@ -18,4 +18,21 @@ describe Taza::Fixtures do
18
18
  examples(:first_example).user.name.should eql(users(:shatner).name)
19
19
  end
20
20
 
21
- end
21
+ it "should be able to resolve one to many relationships" do
22
+ foos(:gap).examples.length.should eql(2)
23
+ end
24
+
25
+ it "should be able to get one to many entities" do
26
+ foos(:gap).examples['first_example'].name.should eql('first')
27
+ foos(:gap).examples['second_example'].name.should eql('second')
28
+ end
29
+
30
+ it "should not be able to access fixtures in sub-folders if not included" do
31
+ lambda{bars(:foo)}.should raise_error(NoMethodError)
32
+ end
33
+
34
+ it "should template fixture files" do
35
+ users(:shatner).age.should eql(66)
36
+ end
37
+
38
+ end
@@ -5,4 +5,8 @@ first_example:
5
5
  second_example:
6
6
  name: second
7
7
  price: 2
8
- user: shatner
8
+ user: shatner
9
+ third_example:
10
+ name: third
11
+ price: 3
12
+ user: shatner
@@ -0,0 +1,2 @@
1
+ foo:
2
+ name: "foo"
@@ -0,0 +1,3 @@
1
+ gap:
2
+ examples: first_example, second_example
3
+
@@ -1,2 +1,3 @@
1
1
  shatner:
2
- name: William Shatner
2
+ name: William Shatner
3
+ age: <%=65+1%>
@@ -0,0 +1,15 @@
1
+ require 'spec/spec_helper'
2
+ require 'taza/fixture'
3
+
4
+ describe "Site Specific Fixtures" do
5
+ include Taza::Fixtures::FooSite
6
+
7
+ it "should be able to access fixtures in sub-folders" do
8
+ bars(:foo).name.should eql("foo")
9
+ end
10
+
11
+ it "should not be able to access non-site-specific fixtures" do
12
+ lambda{foos(:gap)}.should raise_error(NoMethodError)
13
+ end
14
+
15
+ end
@@ -13,6 +13,15 @@ describe "Taza Tasks" do
13
13
 
14
14
  before :each do
15
15
  Dir.stubs(:taglob).returns([])
16
+ Dir.expects(:glob).with('./spec/*/').returns(['./spec/functional/'])
17
+ Dir.expects(:glob).with('./spec/functional/*/').returns(['./spec/functional/foo/'])
18
+ Dir.expects(:glob).with('./spec/functional/*_spec.rb').returns([])
19
+ Dir.expects(:glob).with('./spec/functional/foo/*/').returns(['./spec/functional/foo/page/'])
20
+ Dir.expects(:glob).with('./spec/functional/foo/*_spec.rb').returns([])
21
+ Dir.expects(:glob).with('./spec/functional/foo/page/*/').returns([])
22
+ Dir.expects(:glob).with('./spec/functional/foo/page/*_spec.rb').returns(['./spec/functional/foo/page/bar_spec.rb'])
23
+ load @file_name
24
+ Taza::Rake::Tasks.new
16
25
  end
17
26
 
18
27
  after :all do
@@ -20,21 +29,16 @@ describe "Taza Tasks" do
20
29
  end
21
30
 
22
31
  it "should create rake spec tasks for all sites" do
23
- Dir.stubs(:glob).with('./spec/functional/*/').returns(['./spec/functional/foo/'])
24
- Dir.stubs(:glob).with('./spec/functional/foo/*_spec.rb').returns([])
25
- load @file_name
26
- Taza::Rake::Tasks.new
27
32
  tasks.include?("spec:functional:foo").should be_true
28
33
  end
29
34
 
30
35
  it "should create rake spec tasks for all sites page specs" do
31
- Dir.expects(:glob).with('./spec/functional/*/').returns(['./spec/functional/foo/'])
32
- Dir.expects(:glob).with('./spec/functional/foo/*_spec.rb').returns(['./spec/functional/foo/page_spec.rb'])
33
- load @file_name
34
- Taza::Rake::Tasks.new
35
36
  tasks.include?("spec:functional:foo:page").should be_true
36
37
  end
37
38
 
39
+ it "should create rake spec tasks for all sites page specs in sub-folders" do
40
+ tasks.include?("spec:functional:foo:page:bar").should be_true
41
+ end
38
42
 
39
43
  def tasks
40
44
  @rake.tasks.collect{|task| task.name }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: taza
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.3
4
+ version: 0.8.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Anderson
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-26 00:00:00 -08:00
12
+ date: 2009-02-16 00:00:00 -08:00
13
13
  default_executable: taza
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -137,6 +137,9 @@ files:
137
137
  - spec/sandbox/config.yml
138
138
  - spec/sandbox/fixtures
139
139
  - spec/sandbox/fixtures/examples.yml
140
+ - spec/sandbox/fixtures/foo_site
141
+ - spec/sandbox/fixtures/foo_site/bars.yml
142
+ - spec/sandbox/fixtures/foos.yml
140
143
  - spec/sandbox/fixtures/users.yml
141
144
  - spec/sandbox/flows
142
145
  - spec/sandbox/flows/batman.rb
@@ -147,6 +150,7 @@ files:
147
150
  - spec/sandbox/pages/foo/partials
148
151
  - spec/sandbox/pages/foo/partials/partial_the_reckoning.rb
149
152
  - spec/settings_spec.rb
153
+ - spec/site_fixtures_spec.rb
150
154
  - spec/site_generator_spec.rb
151
155
  - spec/site_spec.rb
152
156
  - spec/spec_helper.rb
@@ -161,6 +165,8 @@ post_install_message:
161
165
  rdoc_options:
162
166
  - --main
163
167
  - README
168
+ - --inline-source
169
+ - --charset=UTF-8
164
170
  require_paths:
165
171
  - lib
166
172
  required_ruby_version: !ruby/object:Gem::Requirement