Module: Blueprints

Defined in:
lib/blueprints.rb,
lib/blueprints/errors.rb,
lib/blueprints/helper.rb,
lib/blueprints/context.rb,
lib/blueprints/blueprint.rb,
lib/blueprints/buildable.rb,
lib/blueprints/namespace.rb,
lib/blueprints/convertable.rb,
lib/blueprints/file_context.rb,
lib/blueprints/configuration.rb,
lib/blueprints/root_namespace.rb,
lib/blueprints/convertable/fixtures.rb

Defined Under Namespace

Modules: Blueprintable, Convertable, Helper, Saveable Classes: Blueprint, BlueprintNotFoundError, Buildable, Configuration, Context, Converter, DemolishError, Dependency, Error, FileContext, FixturesConverter, Namespace, RootNamespace

Class Method Summary collapse

Class Method Details

.backtrace_cleanerObject



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/blueprints.rb', line 57

def self.backtrace_cleaner
  @backtrace_cleaner ||= ActiveSupport::BacktraceCleaner.new.tap do |bc|
    root_sub = /^#{config.root}[\\\/]/
    blueprints_path = File.dirname(__FILE__).sub(root_sub, '')

    bc.add_filter { |line| line.sub(root_sub, '') }

    bc.add_silencer { |line| File.dirname(line).starts_with?(blueprints_path) }
    bc.add_silencer { |line| Gem.path.any? { |path| File.dirname(line).starts_with?(path) } }
  end
end

.configObject

Contains current configuration of blueprints



13
14
15
# File 'lib/blueprints.rb', line 13

def self.config
  @@config ||= Blueprints::Configuration.new
end

.enable {|config| ... } ⇒ Object

Enables blueprints support for RSpec or Test::Unit depending on whether ®Spec is defined or not. Yields Blueprints::Configuration object that you can use to configure blueprints.

Yields:



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/blueprints.rb', line 31

def self.enable
  yield config if block_given?
  load
  extension = if defined? Cucumber
                'cucumber'
              elsif defined? Spec or defined? RSpec
                'rspec'
              else
                'test_unit'
              end
  require File.join(File.dirname(__FILE__), 'blueprints', 'extensions', extension)
end

.loadObject

Sets up configuration, clears database, runs scenarios that have to be prebuilt. Should be run before all test cases and before Blueprints#setup.



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/blueprints.rb', line 45

def self.load
  return unless Namespace.root.empty?

  if_orm do
    DatabaseCleaner.clean_with :truncation
    DatabaseCleaner.strategy = (config.transactions ? :transaction : :truncation)
  end
  load_scenarios_files(config.filename)

  Namespace.root.prebuild(config.prebuild) if config.transactions
end

.setup(current_context) ⇒ Object

Setups variables from global context and starts transaction. Should be called before every test case.



18
19
20
21
22
# File 'lib/blueprints.rb', line 18

def self.setup(current_context)
  Namespace.root.setup
  Namespace.root.copy_ivars(current_context)
  if_orm { DatabaseCleaner.start }
end

.teardownObject

Rollbacks transaction returning everything to state before test. Should be called after every test case.



25
26
27
# File 'lib/blueprints.rb', line 25

def self.teardown
  if_orm { DatabaseCleaner.clean }
end

.warn(message, blueprint) ⇒ Object



69
70
71
72
# File 'lib/blueprints.rb', line 69

def self.warn(message, blueprint)
  $stderr.puts("**WARNING** #{message}: '#{blueprint.name}'")
  $stderr.puts(backtrace_cleaner.clean(blueprint.backtrace(caller)).first)
end