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/configuration.rb,
lib/blueprints/root_namespace.rb,
lib/blueprints/extensions/rspec.rb,
lib/blueprints/convertable/fixtures.rb,
lib/generators/blueprints/model/model_generator.rb
Overview
Main namespace of blueprints. Contains methods for Blueprints setup.
Defined Under Namespace
Modules: Convertable, DescribeHelper, Extensions, Helper Classes: Blueprint, BlueprintNameProxy, BlueprintNotFoundError, Buildable, Configuration, Context, Converter, DemolishError, Dependency, Error, FixturesConverter, ModelGenerator, Namespace, Railtie, RootNamespace
Constant Summary collapse
- VERSION =
'1.0.1'
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.
78 79 80 81 82 83 84 85 86 |
# File 'lib/blueprints.rb', line 78 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)).start_with?(path) } } end end |
.config ⇒ Blueprints::Configuration
Contains current configuration of blueprints
30 31 32 |
# File 'lib/blueprints.rb', line 30 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.
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/blueprints.rb', line 50 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.
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/blueprints.rb', line 64 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.
99 100 101 102 103 104 |
# File 'lib/blueprints.rb', line 99 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.
36 37 38 39 |
# File 'lib/blueprints.rb', line 36 def self.setup(current_context) Namespace.root.setup(current_context) if_orm { DatabaseCleaner.start } end |
.teardown ⇒ Object
Rollbacks transaction returning everything to state before test. Should be called after every test case.
42 43 44 |
# File 'lib/blueprints.rb', line 42 def self.teardown if_orm { DatabaseCleaner.clean } end |
.unused ⇒ Array<String>
Returns array of blueprints that have not been used until now.
90 91 92 |
# File 'lib/blueprints.rb', line 90 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).
109 110 111 112 |
# File 'lib/blueprints.rb', line 109 def self.warn(, blueprint) $stderr.puts("**WARNING** #{}: '#{blueprint.name}'") $stderr.puts(backtrace_cleaner.clean(caller).first) end |