blueprints 0.6.3 → 0.7.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.
@@ -18,10 +18,10 @@ module Blueprints
18
18
  child.namespace = self
19
19
  end
20
20
 
21
- # Finds child by relative name. Raises PlanNotFoundError if child can't be found.
21
+ # Finds child by relative name. Raises BlueprintNotFoundError if child can't be found.
22
22
  def [](path)
23
23
  child_name, path = path.to_s.split('.', 2)
24
- child = @children[child_name.to_sym] or raise PlanNotFoundError, child_name
24
+ child = @children[child_name.to_sym] or raise BlueprintNotFoundError, child_name
25
25
  if path
26
26
  child[path]
27
27
  else
@@ -3,12 +3,12 @@ module Blueprints
3
3
  # building blueprints/namespaces by name. Is also used for copying instance variables between blueprints/contexts/global
4
4
  # context.
5
5
  class RootNamespace < Namespace
6
- attr_reader :context, :plans
7
- attr_accessor :executed_plans
6
+ attr_reader :context, :blueprints
7
+ attr_accessor :executed_blueprints
8
8
 
9
9
  def initialize
10
- @executed_plans = Set.new
11
- @global_executed_plans = Set.new
10
+ @executed_blueprints = Set.new
11
+ @global_executed_blueprints = Set.new
12
12
  @auto_iv_list = Set.new
13
13
 
14
14
  super ''
@@ -17,8 +17,12 @@ module Blueprints
17
17
  # Loads all instance variables from global context to current one.
18
18
  def setup
19
19
  @context = Blueprints::Context.new
20
- Marshal.load(@global_variables).each { |name, value| @context.instance_variable_set(name, value) }
21
- @executed_plans = @global_executed_plans.clone
20
+ @executed_blueprints = @global_executed_blueprints.clone
21
+ if Blueprints.config.transactions
22
+ Marshal.load(@global_variables).each { |name, value| @context.instance_variable_set(name, value) }
23
+ else
24
+ build(Blueprints.config.prebuild)
25
+ end
22
26
  end
23
27
 
24
28
  # Copies all instance variables from current context to another one.
@@ -29,10 +33,10 @@ module Blueprints
29
33
  end
30
34
 
31
35
  # Sets up global context and executes prebuilt blueprints against it.
32
- def prebuild(plans)
36
+ def prebuild(blueprints)
33
37
  @context = Blueprints::Context.new
34
- @global_scenarios = build(plans) if plans
35
- @global_executed_plans = @executed_plans
38
+ @global_scenarios = build(blueprints) if blueprints
39
+ @global_executed_blueprints = @executed_blueprints
36
40
 
37
41
  @global_variables = Marshal.dump(@context.instance_variables.each_with_object({}) {|iv, hash| hash[iv] = @context.instance_variable_get(iv) })
38
42
  end
@@ -1,16 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
3
  describe Blueprints do
4
- describe "constants" do
5
- it "should be loaded from specified dirs" do
6
- Blueprints::PLAN_FILES.should == ["blueprint.rb", "blueprint/*.rb", "spec/blueprint.rb", "spec/blueprint/*.rb", "test/blueprint.rb", "test/blueprint/*.rb"]
7
- end
8
-
9
- it "should support required ORMS" do
10
- Blueprints.supported_orms.should =~ [:active_record, :none]
11
- end
12
- end
13
-
14
4
  it "should return result of built scenario when calling build" do
15
5
  fruit = build :fruit
16
6
  fruit.should == @fruit
@@ -131,32 +121,7 @@ describe Blueprints do
131
121
  it "should raise error when not executed scenarios passed to :undo option" do
132
122
  lambda {
133
123
  demolish :undo => :orange
134
- }.should raise_error(Blueprints::PlanNotFoundError, "Plan/namespace not found 'orange'")
135
- end
136
- end
137
-
138
- describe 'delete policies' do
139
- before do
140
- Blueprints::Namespace.root.stubs(:empty?).returns(true)
141
- Blueprints.stubs(:load_scenarios_files).with(Blueprints::PLAN_FILES)
142
- Blueprints::Namespace.root.stubs(:prebuild).with(nil)
143
- end
144
-
145
- after do
146
- Blueprints.send(:class_variable_set, :@@delete_policy, nil)
147
- end
148
-
149
- it "should allow using custom delete policy" do
150
- ActiveRecord::Base.connection.expects(:delete).with("TRUNCATE fruits")
151
- ActiveRecord::Base.connection.expects(:delete).with("TRUNCATE trees")
152
-
153
- Blueprints.load(:delete_policy => :truncate)
154
- end
155
-
156
- it "should raise an error if unexisting delete policy given" do
157
- lambda {
158
- Blueprints.load(:delete_policy => :unknown)
159
- }.should raise_error(ArgumentError, 'Unknown delete policy unknown')
124
+ }.should raise_error(Blueprints::BlueprintNotFoundError, "Blueprint/namespace not found 'orange'")
160
125
  end
161
126
  end
162
127
 
@@ -202,26 +167,19 @@ describe Blueprints do
202
167
  it 'should raise ScenarioNotFoundError when scenario could not be found' do
203
168
  lambda {
204
169
  build :not_existing
205
- }.should raise_error(Blueprints::PlanNotFoundError, "Plan/namespace not found 'not_existing'")
170
+ }.should raise_error(Blueprints::BlueprintNotFoundError, "Blueprint/namespace not found 'not_existing'")
206
171
  end
207
172
 
208
173
  it 'should raise ScenarioNotFoundError when scenario parent could not be found' do
209
174
  lambda {
210
175
  build :parent_not_existing
211
- }.should raise_error(Blueprints::PlanNotFoundError, "Plan/namespace not found 'not_existing'")
176
+ }.should raise_error(Blueprints::BlueprintNotFoundError, "Blueprint/namespace not found 'not_existing'")
212
177
  end
213
178
 
214
179
  it 'should raise TypeError when scenario name is not symbol or string' do
215
180
  lambda {
216
- Blueprints::Plan.new(1)
217
- }.should raise_error(TypeError, "Pass plan names as strings or symbols only, cannot build plan 1")
218
- end
219
-
220
- it "should raise ArgumentError when unknown ORM specified" do
221
- Blueprints::Namespace.root.expects(:empty?).returns(true)
222
- lambda {
223
- Blueprints.load(:orm => :unknown)
224
- }.should raise_error(ArgumentError, "Unsupported ORM unknown. Blueprints supports only #{Blueprints.supported_orms.join(', ')}")
181
+ Blueprints::Blueprint.new(1)
182
+ }.should raise_error(TypeError, "Pass blueprint names as strings or symbols only, cannot define blueprint 1")
225
183
  end
226
184
  end
227
185
 
@@ -395,8 +353,8 @@ describe Blueprints do
395
353
  it "should warn when blueprint with same name exists" do
396
354
  STDERR.expects(:puts).with("**WARNING** Overwriting existing blueprint: 'overwritten'")
397
355
  STDERR.expects(:puts).with(regexp_matches(/blueprints_(spec|test)\.rb:\d+:in `new'/))
398
- Blueprints::Plan.new(:overwritten)
399
- Blueprints::Plan.new(:overwritten)
356
+ Blueprints::Blueprint.new(:overwritten)
357
+ Blueprints::Blueprint.new(:overwritten)
400
358
  end
401
359
 
402
360
  it "should warn when building with options and blueprint is already built" do
@@ -28,5 +28,10 @@ require 'spec/active_record/fixtures/tree'
28
28
 
29
29
  config_class.configure do |config|
30
30
  config.mock_with :mocha
31
- config.enable_blueprints :root => File.expand_path(File.join(File.dirname(__FILE__))), :prebuild => :big_cherry
31
+ end
32
+
33
+ Blueprints.enable do |config|
34
+ config.root = File.expand_path(File.join(File.dirname(__FILE__)))
35
+ config.prebuild = :big_cherry
36
+ config.transactions = !ENV["NO_TRANSACTIONS"]
32
37
  end
@@ -6,5 +6,10 @@ require 'spec/no_db/fixtures/fruit'
6
6
 
7
7
  Spec::Runner.configure do |config|
8
8
  config.mock_with :mocha
9
- config.enable_blueprints :root => File.expand_path(File.join(File.dirname(__FILE__))), :prebuild => :big_cherry, :orm => :none
9
+ end
10
+
11
+ Blueprints.enable do |config|
12
+ config.root = File.expand_path(File.join(File.dirname(__FILE__)))
13
+ config.prebuild = :big_cherry
14
+ config.orm = nil
10
15
  end
@@ -0,0 +1,32 @@
1
+ function e {
2
+ echo ''
3
+ echo '----------------------------------------'
4
+ echo $1
5
+ echo '----------------------------------------'
6
+ }
7
+
8
+ e "Normal spec"
9
+ spec spec/active_record/blueprints_spec.rb
10
+
11
+ e "Without transactions"
12
+ NO_TRANSACTIONS=true spec spec/active_record/blueprints_spec.rb
13
+
14
+ e "With Rails 3"
15
+ rvm 1.8.7
16
+ RAILS=3 rspec spec/active_record/blueprints_spec.rb
17
+
18
+ e "With no db"
19
+ spec spec/no_db/blueprints_spec.rb
20
+
21
+ e "With Test::Unit"
22
+ ruby test/blueprints_test.rb
23
+
24
+ e "With ruby 1.9.1"
25
+ rvm use 1.9.1
26
+ spec spec/active_record/blueprints_spec.rb
27
+
28
+ e "With ruby 1.8.6"
29
+ rvm use 1.8.6
30
+ spec spec/active_record/blueprints_spec.rb
31
+
32
+ rvm use system
@@ -0,0 +1,34 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe Blueprints::Configuration do
4
+ before do
5
+ @config = Blueprints::Configuration.new
6
+ end
7
+
8
+ it "should have filename with default value" do
9
+ @config.filename.should == ["blueprint.rb", "blueprint/*.rb", "spec/blueprint.rb", "spec/blueprint/*.rb", "test/blueprint.rb", "test/blueprint/*.rb"]
10
+ end
11
+
12
+ it "should have correct attribute values" do
13
+ @config.orm.should == :active_record
14
+ @config.prebuild.should == []
15
+ @config.transactions.should be_true
16
+ @config.root.should be_nil
17
+ end
18
+
19
+ it "should use RAILS_ROOT for root if it's defined" do
20
+ Object::RAILS_ROOT = 'rails/root'
21
+ Blueprints::Configuration.new.root.should == 'rails/root'
22
+ Object.send(:remove_const, :RAILS_ROOT)
23
+ end
24
+
25
+ it "should allow to set only supported orm" do
26
+ Blueprints::Configuration::SUPPORTED_ORMS.should == [nil, :active_record]
27
+ @config.orm = nil
28
+ @config.orm.should be_nil
29
+
30
+ lambda {
31
+ @config.orm = :not_existing
32
+ }.should raise_error(ArgumentError, 'Unsupported ORM :not_existing. Blueprints supports only nil, :active_record')
33
+ end
34
+ end
@@ -0,0 +1,17 @@
1
+ #require 'logger'
2
+ #require 'active_record'
3
+
4
+ Dir.chdir File.join(File.dirname(__FILE__), '..', '..')
5
+
6
+ #ActiveRecord::Base.logger = Logger.new("debug.log")
7
+
8
+ #databases = YAML::load(IO.read("spec/active_record/fixtures/database.yml"))
9
+ #db_info = databases[ENV["DB"] || "test"]
10
+ #ActiveRecord::Base.establish_connection(db_info)
11
+
12
+ require 'spec'
13
+ require 'lib/blueprints'
14
+
15
+ Spec::Runner.configure do |config|
16
+ config.mock_with :mocha
17
+ end
@@ -1,16 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/test_helper'
2
2
 
3
3
  class BlueprintsTest < ActiveSupport::TestCase
4
- context "constants" do
5
- should "be loaded from specified dirs" do
6
- assert(Blueprints::PLAN_FILES == ["blueprint.rb", "blueprint/*.rb", "spec/blueprint.rb", "spec/blueprint/*.rb", "test/blueprint.rb", "test/blueprint/*.rb"])
7
- end
8
-
9
- should "support required ORMS" do
10
- assert_similar(Blueprints.supported_orms, [:active_record, :none])
11
- end
12
- end
13
-
14
4
  should "return result of built scenario when calling build" do
15
5
  fruit = build :fruit
16
6
  assert(fruit == @fruit)
@@ -129,37 +119,12 @@ class BlueprintsTest < ActiveSupport::TestCase
129
119
  end
130
120
 
131
121
  should "raise error when not executed scenarios passed to :undo option" do
132
- assert_raise(Blueprints::PlanNotFoundError, "Plan/namespace not found 'orange'") do
122
+ assert_raise(Blueprints::BlueprintNotFoundError, "Blueprint/namespace not found 'orange'") do
133
123
  demolish :undo => :orange
134
124
  end
135
125
  end
136
126
  end
137
127
 
138
- context 'delete policies' do
139
- setup do
140
- Blueprints::Namespace.root.stubs(:empty?).returns(true)
141
- Blueprints.stubs(:load_scenarios_files).with(Blueprints::PLAN_FILES)
142
- Blueprints::Namespace.root.stubs(:prebuild).with(nil)
143
- end
144
-
145
- teardown do
146
- Blueprints.send(:class_variable_set, :@@delete_policy, nil)
147
- end
148
-
149
- should "allow using custom delete policy" do
150
- ActiveRecord::Base.connection.expects(:delete).with("TRUNCATE fruits")
151
- ActiveRecord::Base.connection.expects(:delete).with("TRUNCATE trees")
152
-
153
- Blueprints.load(:delete_policy => :truncate)
154
- end
155
-
156
- should "raise an error if unexisting delete policy given" do
157
- assert_raise(ArgumentError, 'Unknown delete policy unknown') do
158
- Blueprints.load(:delete_policy => :unknown)
159
- end
160
- end
161
- end
162
-
163
128
  context 'with many apples scenario' do
164
129
  setup do
165
130
  build :many_apples, :cherry, :cherry_basket
@@ -200,27 +165,20 @@ class BlueprintsTest < ActiveSupport::TestCase
200
165
 
201
166
  context 'errors' do
202
167
  should 'raise ScenarioNotFoundError when scenario could not be found' do
203
- assert_raise(Blueprints::PlanNotFoundError, "Plan/namespace not found 'not_existing'") do
168
+ assert_raise(Blueprints::BlueprintNotFoundError, "Blueprint/namespace not found 'not_existing'") do
204
169
  build :not_existing
205
170
  end
206
171
  end
207
172
 
208
173
  should 'raise ScenarioNotFoundError when scenario parent could not be found' do
209
- assert_raise(Blueprints::PlanNotFoundError, "Plan/namespace not found 'not_existing'") do
174
+ assert_raise(Blueprints::BlueprintNotFoundError, "Blueprint/namespace not found 'not_existing'") do
210
175
  build :parent_not_existing
211
176
  end
212
177
  end
213
178
 
214
179
  should 'raise TypeError when scenario name is not symbol or string' do
215
- assert_raise(TypeError, "Pass plan names as strings or symbols only, cannot build plan 1") do
216
- Blueprints::Plan.new(1)
217
- end
218
- end
219
-
220
- should "raise ArgumentError when unknown ORM specified" do
221
- Blueprints::Namespace.root.expects(:empty?).returns(true)
222
- assert_raise(ArgumentError, "Unsupported ORM unknown. Blueprints supports only #{Blueprints.supported_orms.join(', ')}") do
223
- Blueprints.load(:orm => :unknown)
180
+ assert_raise(TypeError, "Pass blueprint names as strings or symbols only, cannot define blueprint 1") do
181
+ Blueprints::Blueprint.new(1)
224
182
  end
225
183
  end
226
184
  end
@@ -395,8 +353,8 @@ class BlueprintsTest < ActiveSupport::TestCase
395
353
  should "warn when blueprint with same name exists" do
396
354
  STDERR.expects(:puts).with("**WARNING** Overwriting existing blueprint: 'overwritten'")
397
355
  STDERR.expects(:puts).with(regexp_matches(/blueprints_(spec|test)\.rb:\d+:in `new'/))
398
- Blueprints::Plan.new(:overwritten)
399
- Blueprints::Plan.new(:overwritten)
356
+ Blueprints::Blueprint.new(:overwritten)
357
+ Blueprints::Blueprint.new(:overwritten)
400
358
  end
401
359
 
402
360
  should "warn when building with options and blueprint is already built" do
@@ -22,10 +22,14 @@ require 'spec/active_record/fixtures/fruit'
22
22
  require 'spec/active_record/fixtures/tree'
23
23
 
24
24
  class ActiveSupport::TestCase
25
- enable_blueprints :root => File.join(File.dirname(__FILE__), '..'), :prebuild => :big_cherry, :filename => 'spec/active_record/blueprint.rb'
26
-
27
25
  def assert_similar(array1, array2)
28
26
  assert (array1 - array2).empty?, "Extra elements #{array1 - array2}"
29
27
  assert (array2 - array1).empty?, "Missing elements #{array2 - array1}"
30
28
  end
31
29
  end
30
+
31
+ Blueprints.enable do |config|
32
+ config.root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
33
+ config.prebuild = :big_cherry
34
+ config.filename = 'spec/active_record/blueprint.rb'
35
+ end
metadata CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 6
9
- - 3
10
- version: 0.6.3
8
+ - 7
9
+ - 1
10
+ version: 0.7.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andrius Chamentauskas
@@ -15,14 +15,45 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-03 00:00:00 +03:00
19
- default_executable:
20
- dependencies: []
21
-
18
+ date: 2010-07-12 00:00:00 +03:00
19
+ default_executable: blueprintify
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: activesupport
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 2
32
+ - 3
33
+ - 0
34
+ version: 2.3.0
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: database_cleaner
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 11
46
+ segments:
47
+ - 0
48
+ - 5
49
+ - 0
50
+ version: 0.5.0
51
+ type: :runtime
52
+ version_requirements: *id002
22
53
  description: Another replacement for factories and fixtures. The library that lazy typists will love
23
54
  email: sinsiliux@gmail.com
24
- executables: []
25
-
55
+ executables:
56
+ - blueprintify
26
57
  extensions: []
27
58
 
28
59
  extra_rdoc_files:
@@ -34,22 +65,25 @@ files:
34
65
  - README.rdoc
35
66
  - Rakefile
36
67
  - VERSION
68
+ - bin/blueprintify
37
69
  - blueprints.gemspec
38
70
  - init.rb
39
71
  - install.rb
40
72
  - lib/blueprints.rb
73
+ - lib/blueprints/blueprint.rb
41
74
  - lib/blueprints/buildable.rb
75
+ - lib/blueprints/configuration.rb
42
76
  - lib/blueprints/context.rb
43
- - lib/blueprints/database_backends/abstract.rb
77
+ - lib/blueprints/convertable.rb
78
+ - lib/blueprints/convertable/fixtures.rb
44
79
  - lib/blueprints/database_backends/active_record.rb
45
- - lib/blueprints/database_backends/none.rb
46
80
  - lib/blueprints/errors.rb
81
+ - lib/blueprints/extensions/deprecated.rb
47
82
  - lib/blueprints/extensions/rspec.rb
48
83
  - lib/blueprints/extensions/test_unit.rb
49
84
  - lib/blueprints/file_context.rb
50
85
  - lib/blueprints/helper.rb
51
86
  - lib/blueprints/namespace.rb
52
- - lib/blueprints/plan.rb
53
87
  - lib/blueprints/root_namespace.rb
54
88
  - spec/active_record/blueprint.rb
55
89
  - spec/active_record/blueprints_spec.rb
@@ -62,6 +96,9 @@ files:
62
96
  - spec/no_db/blueprints_spec.rb
63
97
  - spec/no_db/fixtures/fruit.rb
64
98
  - spec/no_db/spec_helper.rb
99
+ - spec/test_all.sh
100
+ - spec/unit/configuration_spec.rb
101
+ - spec/unit/spec_helper.rb
65
102
  - test/blueprints_test.rb
66
103
  - test/test_helper.rb
67
104
  - uninstall.rb
@@ -104,6 +141,8 @@ test_files:
104
141
  - spec/no_db/spec_helper.rb
105
142
  - spec/no_db/blueprints_spec.rb
106
143
  - spec/no_db/blueprint.rb
144
+ - spec/unit/spec_helper.rb
145
+ - spec/unit/configuration_spec.rb
107
146
  - spec/active_record/fixtures/fruit.rb
108
147
  - spec/active_record/fixtures/tree.rb
109
148
  - spec/active_record/fixtures/schema.rb