blueprints 0.6.2 → 0.6.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/Rakefile +50 -0
- data/VERSION +1 -1
- data/blueprints.gemspec +1 -3
- data/lib/blueprints.rb +3 -0
- data/lib/blueprints/buildable.rb +11 -1
- data/lib/blueprints/context.rb +1 -0
- data/lib/blueprints/extensions/rspec.rb +20 -3
- data/lib/blueprints/helper.rb +5 -0
- data/lib/blueprints/namespace.rb +4 -0
- data/spec/active_record/blueprints_spec.rb +2 -2
- data/test/blueprints_test.rb +18 -1
- metadata +3 -5
- data/script/load_schema +0 -14
- data/script/rspec_to_test +0 -29
data/Rakefile
CHANGED
@@ -19,3 +19,53 @@ Rake::RDocTask.new do |rd|
|
|
19
19
|
rd.main = "README.rdoc"
|
20
20
|
rd.rdoc_files.include("README.rdoc", "lib/**/*.rb")
|
21
21
|
end
|
22
|
+
|
23
|
+
namespace :db do
|
24
|
+
desc "Create database structure"
|
25
|
+
task :prepare do
|
26
|
+
require 'rubygems'
|
27
|
+
require 'active_record'
|
28
|
+
|
29
|
+
Dir.chdir File.dirname(__FILE__)
|
30
|
+
|
31
|
+
ActiveRecord::Base.logger = Logger.new("debug.log")
|
32
|
+
|
33
|
+
databases = YAML::load(IO.read("spec/active_record/fixtures/database.yml"))
|
34
|
+
db_info = databases[ENV["DB"] || "test"]
|
35
|
+
ActiveRecord::Base.establish_connection(db_info)
|
36
|
+
|
37
|
+
load("spec/active_record/fixtures/schema.rb")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
desc "Convert rspec specs to test/unit tests"
|
42
|
+
task :rspec_to_test do
|
43
|
+
Dir.chdir File.dirname(__FILE__)
|
44
|
+
data = IO.read('spec/active_record/blueprints_spec.rb')
|
45
|
+
|
46
|
+
data.gsub!("require File.dirname(__FILE__) + '/spec_helper'", "require File.dirname(__FILE__) + '/test_helper'")
|
47
|
+
data.gsub!("describe Blueprints do", 'class BlueprintsTest < ActiveSupport::TestCase')
|
48
|
+
|
49
|
+
# lambda {
|
50
|
+
# hornsby_clear :undo => :just_orange
|
51
|
+
# }.should raise_error(ArgumentError)
|
52
|
+
data.gsub!(/(\s+)lambda \{\n(.*)\n(\s+)\}.should raise_error\((.*)\)/, "\\1assert_raise(\\4) do\n\\2\n\\3end")
|
53
|
+
# should =~ => assert_similar
|
54
|
+
data.gsub!(/^(\s+)(.*)\.should\s*=~\s*(.*)/, '\1assert_similar(\2, \3)')
|
55
|
+
|
56
|
+
# .should_not => assert(!())
|
57
|
+
data.gsub!(/^(\s+)(.*)\.should_not(.*)/, '\1assert(!(\2\3))')
|
58
|
+
# .should => assert()
|
59
|
+
data.gsub!(/^(\s+)(.*)\.should(.*)/, '\1assert(\2\3)')
|
60
|
+
# be_nil => .nil?
|
61
|
+
data.gsub!(/ be_([^\(\)]*)/, '.\1?')
|
62
|
+
# have(2).items => .size == 2
|
63
|
+
data.gsub!(/ have\((\d+)\)\.items/, '.size == \1')
|
64
|
+
|
65
|
+
data.gsub!(/^(\s+)describe/, '\1context')
|
66
|
+
data.gsub!(/^(\s+)it (["'])(should )?/, '\1should \2')
|
67
|
+
data.gsub!(/^(\s+)before.*do/, '\1setup do')
|
68
|
+
data.gsub!(/^(\s+)after.*do/, '\1teardown do')
|
69
|
+
|
70
|
+
File.open('test/blueprints_test.rb', 'w') {|f| f.write(data)}
|
71
|
+
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.6.
|
1
|
+
0.6.3
|
data/blueprints.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{blueprints}
|
8
|
-
s.version = "0.6.
|
8
|
+
s.version = "0.6.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Andrius Chamentauskas"]
|
@@ -39,8 +39,6 @@ Gem::Specification.new do |s|
|
|
39
39
|
"lib/blueprints/namespace.rb",
|
40
40
|
"lib/blueprints/plan.rb",
|
41
41
|
"lib/blueprints/root_namespace.rb",
|
42
|
-
"script/load_schema",
|
43
|
-
"script/rspec_to_test",
|
44
42
|
"spec/active_record/blueprint.rb",
|
45
43
|
"spec/active_record/blueprints_spec.rb",
|
46
44
|
"spec/active_record/fixtures/database.yml.example",
|
data/lib/blueprints.rb
CHANGED
data/lib/blueprints/buildable.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Blueprints
|
2
2
|
class Buildable
|
3
|
-
class Dependency < Struct.new(:name)
|
3
|
+
class Dependency < Struct.new(:name) # :nodoc:
|
4
4
|
alias :to_sym :name
|
5
5
|
|
6
6
|
def iv_name
|
@@ -11,6 +11,10 @@ module Blueprints
|
|
11
11
|
attr_reader :name
|
12
12
|
attr_accessor :namespace
|
13
13
|
|
14
|
+
# Initializes new Buildable object by name.
|
15
|
+
# Name can be Symbol, String or Hash. If Hash is passed, then first key is assumed name, and value(s) of that key
|
16
|
+
# are assumed as dependencies. Raises error class of name parameter is not what is expected.
|
17
|
+
# Warns if name has already been taken.
|
14
18
|
def initialize(name)
|
15
19
|
@name, parents = parse_name(name)
|
16
20
|
depends_on(*parents)
|
@@ -26,6 +30,10 @@ module Blueprints
|
|
26
30
|
end
|
27
31
|
|
28
32
|
# Builds dependencies of blueprint and then blueprint itself.
|
33
|
+
#
|
34
|
+
# +build_once+ - pass false if you want to build despite the fact that it was already built.
|
35
|
+
#
|
36
|
+
# +options+ - list of options to be accessible in the body of a blueprint. Defaults to empty Hash.
|
29
37
|
def build(build_once = true, options = {})
|
30
38
|
each_namespace {|namespace| namespace.build_parents }
|
31
39
|
build_parents
|
@@ -39,6 +47,8 @@ module Blueprints
|
|
39
47
|
end
|
40
48
|
end
|
41
49
|
|
50
|
+
# If value is passed then it sets attributes for this buildable object.
|
51
|
+
# Otherwise returns attributes (defaulting to empty Hash)
|
42
52
|
def attributes(value = nil)
|
43
53
|
if value
|
44
54
|
raise value.inspect + @name if @name == ''
|
data/lib/blueprints/context.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
extend_class.class_eval do
|
1
|
+
# Module that gets included into RSpec Configuration class to provide enable_blueprints method.
|
2
|
+
module Blueprints::RspecMixin
|
4
3
|
# Enables blueprints in rspec. Is automatically added if <tt>Spec</tt> is defined at loading time or <tt>script/spec</tt>
|
5
4
|
# is used. You might need to require it manually in certain case (eg. running specs from metrics).
|
6
5
|
# Accepts options hash. For supported options please check Blueprints.load.
|
@@ -16,3 +15,21 @@ extend_class.class_eval do
|
|
16
15
|
end
|
17
16
|
end
|
18
17
|
end
|
18
|
+
|
19
|
+
if defined?(RSpec)
|
20
|
+
module RSpec #:nodoc:
|
21
|
+
module Core #:nodoc:
|
22
|
+
class Configuration
|
23
|
+
include Blueprints::RspecMixin
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
else
|
28
|
+
module Spec #:nodoc:
|
29
|
+
module Runner #:nodoc:
|
30
|
+
class Configuration
|
31
|
+
include Blueprints::RspecMixin
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/blueprints/helper.rb
CHANGED
@@ -20,6 +20,11 @@ module Blueprints
|
|
20
20
|
Namespace.root.build(names, self, false)
|
21
21
|
end
|
22
22
|
|
23
|
+
# Returns attributes that are used to build blueprint. To set what attributes are used you need to call attributes
|
24
|
+
# method when defining blueprint like this:
|
25
|
+
# blueprint :apple do
|
26
|
+
# Fruit.build attributes
|
27
|
+
# end.attributes(:name => 'apple')
|
23
28
|
def build_attributes(name)
|
24
29
|
Namespace.root[name].attributes
|
25
30
|
end
|
data/lib/blueprints/namespace.rb
CHANGED
@@ -6,16 +6,19 @@ module Blueprints
|
|
6
6
|
attr_reader :children
|
7
7
|
delegate :empty?, :size, :to => :@children
|
8
8
|
|
9
|
+
# Creates namespace by name. See Buildable#new.
|
9
10
|
def initialize(name)
|
10
11
|
super(name)
|
11
12
|
@children = {}
|
12
13
|
end
|
13
14
|
|
15
|
+
# Adds child to namespaces children. Child should be instance of Buildable.
|
14
16
|
def add_child(child)
|
15
17
|
@children[child.name] = child
|
16
18
|
child.namespace = self
|
17
19
|
end
|
18
20
|
|
21
|
+
# Finds child by relative name. Raises PlanNotFoundError if child can't be found.
|
19
22
|
def [](path)
|
20
23
|
child_name, path = path.to_s.split('.', 2)
|
21
24
|
child = @children[child_name.to_sym] or raise PlanNotFoundError, child_name
|
@@ -26,6 +29,7 @@ module Blueprints
|
|
26
29
|
end
|
27
30
|
end
|
28
31
|
|
32
|
+
# Builds all children and sets instance variable named by name of namespace with the results.
|
29
33
|
def build_self(build_once = true)
|
30
34
|
Namespace.root.add_variable(path, @children.collect {|p| p.last.build }.uniq)
|
31
35
|
end
|
@@ -394,14 +394,14 @@ describe Blueprints do
|
|
394
394
|
|
395
395
|
it "should warn when blueprint with same name exists" do
|
396
396
|
STDERR.expects(:puts).with("**WARNING** Overwriting existing blueprint: 'overwritten'")
|
397
|
-
STDERR.expects(:puts).with(regexp_matches(
|
397
|
+
STDERR.expects(:puts).with(regexp_matches(/blueprints_(spec|test)\.rb:\d+:in `new'/))
|
398
398
|
Blueprints::Plan.new(:overwritten)
|
399
399
|
Blueprints::Plan.new(:overwritten)
|
400
400
|
end
|
401
401
|
|
402
402
|
it "should warn when building with options and blueprint is already built" do
|
403
403
|
STDERR.expects(:puts).with("**WARNING** Building with options, but blueprint was already built: 'big_cherry'")
|
404
|
-
STDERR.expects(:puts).with(regexp_matches(
|
404
|
+
STDERR.expects(:puts).with(regexp_matches(/blueprints_(spec|test)\.rb:\d+/))
|
405
405
|
build :big_cherry => {:species => 'some species'}
|
406
406
|
end
|
407
407
|
|
data/test/blueprints_test.rb
CHANGED
@@ -264,6 +264,11 @@ class BlueprintsTest < ActiveSupport::TestCase
|
|
264
264
|
fruits = Fruit.blueprint([{:species => 'fruit1'}, {:species => 'fruit2'}])
|
265
265
|
assert(fruits.collect(&:species) == %w{fruit1 fruit2})
|
266
266
|
end
|
267
|
+
|
268
|
+
should "allow to build oak without attributes" do
|
269
|
+
build :oak_without_attributes
|
270
|
+
assert(@oak_without_attributes.instance_of?(Tree))
|
271
|
+
end
|
267
272
|
end
|
268
273
|
|
269
274
|
context "with pitted namespace" do
|
@@ -360,6 +365,11 @@ class BlueprintsTest < ActiveSupport::TestCase
|
|
360
365
|
assert(@small_acorn == @acorn)
|
361
366
|
end
|
362
367
|
|
368
|
+
should "not reset options after call to build" do
|
369
|
+
build :small_acorn => {:option => 'value'}
|
370
|
+
assert(@small_acorn_options == {:option => 'value'})
|
371
|
+
end
|
372
|
+
|
363
373
|
should "allow to use shortcut to extend blueprint" do
|
364
374
|
build :huge_acorn
|
365
375
|
assert(@huge_acorn.average_diameter == 100)
|
@@ -369,6 +379,11 @@ class BlueprintsTest < ActiveSupport::TestCase
|
|
369
379
|
build :huge_acorn
|
370
380
|
assert(@huge_acorn.tree.size == 'huge')
|
371
381
|
end
|
382
|
+
|
383
|
+
should "allow to pass options when building extended blueprint" do
|
384
|
+
build :huge_acorn => {:average_diameter => 200}
|
385
|
+
assert(@huge_acorn.average_diameter == 200)
|
386
|
+
end
|
372
387
|
end
|
373
388
|
|
374
389
|
should "allow to build! without checking if it was already built" do
|
@@ -378,13 +393,15 @@ class BlueprintsTest < ActiveSupport::TestCase
|
|
378
393
|
end
|
379
394
|
|
380
395
|
should "warn when blueprint with same name exists" do
|
381
|
-
|
396
|
+
STDERR.expects(:puts).with("**WARNING** Overwriting existing blueprint: 'overwritten'")
|
397
|
+
STDERR.expects(:puts).with(regexp_matches(/blueprints_(spec|test)\.rb:\d+:in `new'/))
|
382
398
|
Blueprints::Plan.new(:overwritten)
|
383
399
|
Blueprints::Plan.new(:overwritten)
|
384
400
|
end
|
385
401
|
|
386
402
|
should "warn when building with options and blueprint is already built" do
|
387
403
|
STDERR.expects(:puts).with("**WARNING** Building with options, but blueprint was already built: 'big_cherry'")
|
404
|
+
STDERR.expects(:puts).with(regexp_matches(/blueprints_(spec|test)\.rb:\d+/))
|
388
405
|
build :big_cherry => {:species => 'some species'}
|
389
406
|
end
|
390
407
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blueprints
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 1
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 6
|
9
|
-
-
|
10
|
-
version: 0.6.
|
9
|
+
- 3
|
10
|
+
version: 0.6.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Andrius Chamentauskas
|
@@ -51,8 +51,6 @@ files:
|
|
51
51
|
- lib/blueprints/namespace.rb
|
52
52
|
- lib/blueprints/plan.rb
|
53
53
|
- lib/blueprints/root_namespace.rb
|
54
|
-
- script/load_schema
|
55
|
-
- script/rspec_to_test
|
56
54
|
- spec/active_record/blueprint.rb
|
57
55
|
- spec/active_record/blueprints_spec.rb
|
58
56
|
- spec/active_record/fixtures/database.yml.example
|
data/script/load_schema
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'active_record'
|
5
|
-
|
6
|
-
Dir.chdir File.join(File.dirname(__FILE__), '..')
|
7
|
-
|
8
|
-
ActiveRecord::Base.logger = Logger.new("debug.log")
|
9
|
-
|
10
|
-
databases = YAML::load(IO.read("spec/active_record/fixtures/database.yml"))
|
11
|
-
db_info = databases[ENV["DB"] || "test"]
|
12
|
-
ActiveRecord::Base.establish_connection(db_info)
|
13
|
-
|
14
|
-
load("spec/active_record/fixtures/schema.rb")
|
data/script/rspec_to_test
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
Dir.chdir File.join(File.dirname(__FILE__), '..')
|
3
|
-
data = IO.read('spec/active_record/blueprints_spec.rb')
|
4
|
-
|
5
|
-
data.gsub!("require File.dirname(__FILE__) + '/spec_helper'", "require File.dirname(__FILE__) + '/test_helper'")
|
6
|
-
data.gsub!("describe Blueprints do", 'class BlueprintsTest < ActiveSupport::TestCase')
|
7
|
-
|
8
|
-
# lambda {
|
9
|
-
# hornsby_clear :undo => :just_orange
|
10
|
-
# }.should raise_error(ArgumentError)
|
11
|
-
data.gsub!(/(\s+)lambda \{\n(.*)\n(\s+)\}.should raise_error\((.*)\)/, "\\1assert_raise(\\4) do\n\\2\n\\3end")
|
12
|
-
# should =~ => assert_similar
|
13
|
-
data.gsub!(/^(\s+)(.*)\.should\s*=~\s*(.*)/, '\1assert_similar(\2, \3)')
|
14
|
-
|
15
|
-
# .should_not => assert(!())
|
16
|
-
data.gsub!(/^(\s+)(.*)\.should_not(.*)/, '\1assert(!(\2\3))')
|
17
|
-
# .should => assert()
|
18
|
-
data.gsub!(/^(\s+)(.*)\.should(.*)/, '\1assert(\2\3)')
|
19
|
-
# be_nil => .nil?
|
20
|
-
data.gsub!(/ be_([^\(\)]*)/, '.\1?')
|
21
|
-
# have(2).items => .size == 2
|
22
|
-
data.gsub!(/ have\((\d+)\)\.items/, '.size == \1')
|
23
|
-
|
24
|
-
data.gsub!(/^(\s+)describe/, '\1context')
|
25
|
-
data.gsub!(/^(\s+)it (["'])(should )?/, '\1should \2')
|
26
|
-
data.gsub!(/^(\s+)before.*do/, '\1setup do')
|
27
|
-
data.gsub!(/^(\s+)after.*do/, '\1teardown do')
|
28
|
-
|
29
|
-
File.open('test/blueprints_test.rb', 'w') {|f| f.write(data)}
|