Module: Blueprints
- Defined in:
- lib/blueprints.rb,
lib/blueprints/errors.rb,
lib/blueprints/helper.rb,
lib/blueprints/context.rb,
lib/blueprints/version.rb,
lib/blueprints/blueprint.rb,
lib/blueprints/buildable.rb,
lib/blueprints/namespace.rb,
lib/blueprints/convertable.rb,
lib/blueprints/eval_context.rb,
lib/blueprints/configuration.rb,
lib/blueprints/root_namespace.rb,
lib/blueprints/convertable/fixtures.rb
Overview
Main namespace of blueprints. Contains methods for Blueprints setup.
Defined Under Namespace
Modules: Convertable, Extensions, Helper Classes: Blueprint, BlueprintNotFoundError, Buildable, Configuration, Context, Converter, DemolishError, Dependency, Error, EvalContext, FixturesConverter, Namespace, RootNamespace
Constant Summary collapse
- VERSION =
'0.9.0'
Class Method Summary collapse
-
.backtrace_cleaner ⇒ ActiveSupport::BacktraceCleaner
Returns backtrace cleaner that is used to extract lines from user application.
-
.config ⇒ Blueprints::Configuration
Contains current configuration of blueprints.
-
.enable {|config| ... } ⇒ Object
Enables blueprints support for RSpec or Test::Unit depending on whether ®Spec is defined or not.
-
.load ⇒ Object
Sets up configuration, clears database, runs scenarios that have to be prebuilt.
-
.most_used(options = {}) ⇒ Array<Array<String, Integer>>
Returns array of most used blueprints.
-
.setup(current_context) ⇒ Object
Setups variables from global context and starts transaction.
-
.teardown ⇒ Object
Rollbacks transaction returning everything to state before test.
-
.unused ⇒ Array<String>
Returns array of blueprints that have not been used until now.
-
.warn(message, blueprint) ⇒ Object
Warns a user (often about deprecated feature).
Class Method Details
.backtrace_cleaner ⇒ ActiveSupport::BacktraceCleaner
Returns backtrace cleaner that is used to extract lines from user application.
71 72 73 74 75 76 77 78 79 |
# File 'lib/blueprints.rb', line 71 def self.backtrace_cleaner @backtrace_cleaner ||= ActiveSupport::BacktraceCleaner.new.tap do |bc| root_sub = /^#{config.root}[\\\/]/ blueprints_path = File.(File.dirname(__FILE__)) bc.add_filter { |line| line.sub(root_sub, '') } bc.add_silencer { |line| [blueprints_path, *Gem.path].any? { |path| File.(File.dirname(line)).starts_with?(path) } } end end |
.config ⇒ Blueprints::Configuration
Contains current configuration of blueprints
22 23 24 |
# File 'lib/blueprints.rb', line 22 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.
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/blueprints.rb', line 43 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 |
.load ⇒ Object
Sets up configuration, clears database, runs scenarios that have to be prebuilt. Should be run before all test cases and before Blueprints#setup.
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/blueprints.rb', line 57 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 |
.most_used(options = {}) ⇒ Array<Array<String, Integer>>
Returns array of most used blueprints.
92 93 94 95 96 97 |
# File 'lib/blueprints.rb', line 92 def self.most_used( = {}) blueprints = each_blueprint.collect { |blueprint| [blueprint.full_name, blueprint.uses] }.sort { |a, b| b[1] <=> a[1] } blueprints = blueprints.take([:count]) if [:count] blueprints.reject! { |blueprint| blueprint[1] < [:at_least] } if [:at_least] blueprints end |
.setup(current_context) ⇒ Object
Setups variables from global context and starts transaction. Should be called before every test case.
28 29 30 31 32 |
# File 'lib/blueprints.rb', line 28 def self.setup(current_context) Namespace.root.setup Namespace.root.eval_context.copy_instance_variables(current_context) if_orm { DatabaseCleaner.start } end |
.teardown ⇒ Object
Rollbacks transaction returning everything to state before test. Should be called after every test case.
35 36 37 |
# File 'lib/blueprints.rb', line 35 def self.teardown if_orm { DatabaseCleaner.clean } end |
.unused ⇒ Array<String>
Returns array of blueprints that have not been used until now.
83 84 85 |
# File 'lib/blueprints.rb', line 83 def self.unused each_blueprint.select { |blueprint| blueprint.uses.zero? }.collect(&:full_name) end |
.warn(message, blueprint) ⇒ Object
Warns a user (often about deprecated feature).
102 103 104 105 |
# File 'lib/blueprints.rb', line 102 def self.warn(, blueprint) $stderr.puts("**WARNING** #{}: '#{blueprint.name}'") $stderr.puts(backtrace_cleaner.clean(blueprint.backtrace(caller)).first) end |