blueprints 0.6.1 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.1
1
+ 0.6.2
data/blueprints.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{blueprints}
8
- s.version = "0.6.1"
8
+ s.version = "0.6.2"
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"]
12
- s.date = %q{2010-05-28}
12
+ s.date = %q{2010-07-03}
13
13
  s.description = %q{Another replacement for factories and fixtures. The library that lazy typists will love}
14
14
  s.email = %q{sinsiliux@gmail.com}
15
15
  s.extra_rdoc_files = [
data/lib/blueprints.rb CHANGED
@@ -3,7 +3,7 @@ files = %w{
3
3
  context buildable namespace root_namespace plan file_context helper errors
4
4
  database_backends/abstract database_backends/active_record database_backends/none
5
5
  }
6
- files << if defined? Spec or $0 =~ /script.spec$/
6
+ files << if defined? Spec or $0 =~ /script.spec$/ or defined? RSpec
7
7
  'extensions/rspec'
8
8
  else
9
9
  'extensions/test_unit'
@@ -70,8 +70,22 @@ module Blueprints
70
70
  @@orm.delete_tables(@@delete_policy, *tables)
71
71
  end
72
72
 
73
+ def self.backtrace_cleaner
74
+ @backtrace_cleaner ||= ActiveSupport::BacktraceCleaner.new.tap do |bc|
75
+ root_sub = /^#{@@framework_root}[\\\/]/
76
+ blueprints_path = File.dirname(__FILE__).sub(root_sub, '')
77
+
78
+ bc.add_filter {|line| line.sub('(eval)', @@file) }
79
+ bc.add_filter {|line| line.sub(root_sub, '') }
80
+
81
+ bc.add_silencer {|line| File.dirname(line).starts_with?(blueprints_path) }
82
+ bc.add_silencer {|line| Gem.path.any? {|path| File.dirname(line).starts_with?(path) } }
83
+ end
84
+ end
85
+
73
86
  def self.warn(message, blueprint)
74
87
  $stderr.puts("**WARNING** #{message}: '#{blueprint}'")
88
+ $stderr.puts(backtrace_cleaner.clean(caller).first)
75
89
  end
76
90
 
77
91
  protected
@@ -85,7 +99,10 @@ module Blueprints
85
99
 
86
100
  patterns.each do |pattern|
87
101
  unless (files = Dir.glob(pattern)).empty?
88
- files.each{|f| FileContext.module_eval File.read(f)}
102
+ files.each do |f|
103
+ @@file = f
104
+ FileContext.module_eval File.read(f)
105
+ end
89
106
  FileContext.evaluating = false
90
107
  return
91
108
  end
@@ -30,13 +30,12 @@ module Blueprints
30
30
  each_namespace {|namespace| namespace.build_parents }
31
31
  build_parents
32
32
 
33
- Namespace.root.context.options = options
34
- Namespace.root.context.attributes = attributes.merge(options)
33
+ old_options, old_attributes = Namespace.root.context.options, Namespace.root.context.attributes
34
+ Namespace.root.context.options, Namespace.root.context.attributes = options, attributes.merge(options)
35
35
  each_namespace {|namespace| Namespace.root.context.attributes.reverse_merge! namespace.attributes }
36
36
 
37
37
  build_self(build_once).tap do
38
- Namespace.root.context.options = {}
39
- Namespace.root.context.attributes = {}
38
+ Namespace.root.context.options, Namespace.root.context.attributes = old_options, old_attributes
40
39
  end
41
40
  end
42
41
 
@@ -67,7 +67,9 @@ module Blueprints
67
67
  if name_or_attrs.is_a?(Array)
68
68
  name_or_attrs.collect { |attrs| blueprint(attrs) }
69
69
  else
70
- returning(self.new) { |object| object.blueprint(name_or_attrs) }
70
+ object = new
71
+ object.blueprint(name_or_attrs)
72
+ object
71
73
  end
72
74
  end
73
75
  end
@@ -1,20 +1,18 @@
1
- module Spec #:nodoc:
2
- module Runner #:nodoc:
3
- class Configuration
4
- # Enables blueprints in rspec. Is automatically added if <tt>Spec</tt> is defined at loading time or <tt>script/spec</tt>
5
- # is used. You might need to require it manually in certain case (eg. running specs from metrics).
6
- # Accepts options hash. For supported options please check Blueprints.load.
7
- def enable_blueprints(options = {})
8
- Blueprints.load(options)
1
+ extend_class = defined?(RSpec) ? RSpec::Core::Configuration : Spec::Runner::Configuration
9
2
 
10
- include(Blueprints::Helper)
11
- before do
12
- Blueprints.setup(self)
13
- end
14
- after do
15
- Blueprints.teardown
16
- end
17
- end
3
+ extend_class.class_eval do
4
+ # Enables blueprints in rspec. Is automatically added if <tt>Spec</tt> is defined at loading time or <tt>script/spec</tt>
5
+ # is used. You might need to require it manually in certain case (eg. running specs from metrics).
6
+ # Accepts options hash. For supported options please check Blueprints.load.
7
+ def enable_blueprints(options = {})
8
+ Blueprints.load(options)
9
+
10
+ include(Blueprints::Helper)
11
+ before do
12
+ Blueprints.setup(self)
13
+ end
14
+ after do
15
+ Blueprints.teardown
18
16
  end
19
17
  end
20
18
  end
@@ -26,7 +26,8 @@ module Blueprints
26
26
  # Changes blueprint block to build another blueprint by passing additional options to it. Usually used to dry up
27
27
  # blueprints that are often built with some options.
28
28
  def extends(parent, options)
29
- @block = Proc.new { build parent => options }
29
+ attributes(options)
30
+ @block = Proc.new { build parent => attributes }
30
31
  end
31
32
 
32
33
  private
@@ -44,7 +44,8 @@ end
44
44
 
45
45
  Fruit.blueprint(:acorn, :species => 'Acorn', :tree => d(:oak))
46
46
  blueprint :small_acorn do
47
- build :acorn => {:average_diameter => 1}
47
+ @small_acorn = build :acorn => {:average_diameter => 1}
48
+ @small_acorn_options = options
48
49
  end
49
50
  blueprint(:huge_acorn => :huge_oak).extends(:acorn, :average_diameter => 100)
50
51
 
@@ -365,6 +365,11 @@ describe Blueprints do
365
365
  @small_acorn.should == @acorn
366
366
  end
367
367
 
368
+ it "should not reset options after call to build" do
369
+ build :small_acorn => {:option => 'value'}
370
+ @small_acorn_options.should == {:option => 'value'}
371
+ end
372
+
368
373
  it "should allow to use shortcut to extend blueprint" do
369
374
  build :huge_acorn
370
375
  @huge_acorn.average_diameter.should == 100
@@ -374,6 +379,11 @@ describe Blueprints do
374
379
  build :huge_acorn
375
380
  @huge_acorn.tree.size.should == 'huge'
376
381
  end
382
+
383
+ it "should allow to pass options when building extended blueprint" do
384
+ build :huge_acorn => {:average_diameter => 200}
385
+ @huge_acorn.average_diameter.should == 200
386
+ end
377
387
  end
378
388
 
379
389
  it "should allow to build! without checking if it was already built" do
@@ -383,13 +393,15 @@ describe Blueprints do
383
393
  end
384
394
 
385
395
  it "should warn when blueprint with same name exists" do
386
- $stderr.expects(:puts).with("**WARNING** Overwriting existing blueprint: 'overwritten'")
396
+ STDERR.expects(:puts).with("**WARNING** Overwriting existing blueprint: 'overwritten'")
397
+ STDERR.expects(:puts).with(regexp_matches(/^blueprints_spec\.rb:\d+:in `new'$/))
387
398
  Blueprints::Plan.new(:overwritten)
388
399
  Blueprints::Plan.new(:overwritten)
389
400
  end
390
401
 
391
402
  it "should warn when building with options and blueprint is already built" do
392
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\.rb:\d+$/))
393
405
  build :big_cherry => {:species => 'some species'}
394
406
  end
395
407
 
@@ -1,10 +1,9 @@
1
1
  require 'rubygems'
2
2
  require 'fileutils'
3
+ require 'logger'
4
+ version = ENV['RAILS']
5
+ gem 'activerecord', version == '3' ? '>= 3.0.0.beta' : "~> #{version}" if version
3
6
  require 'active_record'
4
- begin
5
- require 'mysqlplus'
6
- rescue LoadError
7
- end
8
7
 
9
8
  Dir.chdir File.join(File.dirname(__FILE__), '..', '..')
10
9
 
@@ -14,12 +13,20 @@ databases = YAML::load(IO.read("spec/active_record/fixtures/database.yml"))
14
13
  db_info = databases[ENV["DB"] || "test"]
15
14
  ActiveRecord::Base.establish_connection(db_info)
16
15
 
17
- require 'spec/autorun'
16
+ config_class = if version.to_s[0, 1] == '3'
17
+ gem 'rspec', '>= 2.0.0.beta'
18
+ require 'rspec'
19
+ RSpec
20
+ else
21
+ require 'spec'
22
+ Spec::Runner
23
+ end
24
+
18
25
  require 'lib/blueprints'
19
26
  require 'spec/active_record/fixtures/fruit'
20
27
  require 'spec/active_record/fixtures/tree'
21
28
 
22
- Spec::Runner.configure do |config|
29
+ config_class.configure do |config|
23
30
  config.mock_with :mocha
24
31
  config.enable_blueprints :root => File.expand_path(File.join(File.dirname(__FILE__))), :prebuild => :big_cherry
25
32
  end
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: 5
4
+ hash: 3
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 1
10
- version: 0.6.1
9
+ - 2
10
+ version: 0.6.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andrius Chamentauskas
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-05-28 00:00:00 +03:00
18
+ date: 2010-07-03 00:00:00 +03:00
19
19
  default_executable:
20
20
  dependencies: []
21
21