Class: Sniff
- Inherits:
-
Object
- Object
- Sniff
- Defined in:
- lib/sniff.rb,
lib/sniff/fixture.rb,
lib/sniff/version.rb,
lib/sniff/rake_tasks.rb
Defined Under Namespace
Modules: Fixture Classes: RakeTasks
Constant Summary collapse
- VERSION =
"1.1.1"
Instance Attribute Summary collapse
-
#fixtures_path ⇒ Object
Returns the value of attribute fixtures_path.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#options ⇒ Object
Returns the value of attribute options.
-
#project ⇒ Object
Returns the value of attribute project.
-
#root ⇒ Object
Returns the value of attribute root.
-
#test_support_path ⇒ Object
Returns the value of attribute test_support_path.
Class Method Summary collapse
- .init(local_root, options = {}) ⇒ Object
- .logger ⇒ Object
- .logger=(val) ⇒ Object
-
.path(*rest) ⇒ Object
Get a path relative to sniff’s root.
-
.root ⇒ Object
Sniff’s root directory (the gem’s location on the filesystem).
Instance Method Summary collapse
-
#connect ⇒ Object
Connect to the database and set up an ActiveRecord logger.
- #emitter_class ⇒ Object
- #init_cucumber ⇒ Object
-
#initialize(local_root, options = {}) ⇒ Sniff
constructor
Prepares the environment for running tests against Earth data and emitter gems.
- #load_supporting_libs ⇒ Object
- #log(str) ⇒ Object
- #migrate! ⇒ Object
- #seed! ⇒ Object
Constructor Details
#initialize(local_root, options = {}) ⇒ Sniff
Prepares the environment for running tests against Earth data and emitter gems.
local_root: Root directory of the emitter gem to be tested (path to the repo)
options:
-
:logger is a Logger log device used by Sniff and ActiveRecord (default: nil)
logger: nil = no log, string = file path, STDOUT for terminal
-
:fixtures_path is the path to your gem’s fixtures (default: local_root/lib/db/fixtures)
-
:cucumber tells Sniff to load cucumber test support files provided by the emitter in <emitter_root>/test_support/cucumber (default: false)
-
:project is the current project (e.g. ‘flight’). Default is guessed from CWD
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/sniff.rb', line 49 def initialize(local_root, = {}) self.root = local_root self.project = [:project] || File.basename(File.(local_root)) self. = .symbolize_keys self.test_support_path = File.join(root, 'features', 'support') self.fixtures_path = [:fixtures_path] ENV['DATABASE_URL'] ||= "mysql2://root:password@localhost/test_#{project}" load_supporting_libs logger = self.[:logger] || ENV['LOGGER'] Sniff.logger ||= Logger.new logger DataMiner.logger = Sniff.logger DataMiner.unit_converter = :conversions init_cucumber if self.[:cucumber] end |
Instance Attribute Details
#fixtures_path ⇒ Object
Returns the value of attribute fixtures_path.
35 36 37 |
# File 'lib/sniff.rb', line 35 def fixtures_path @fixtures_path end |
#logger ⇒ Object
Returns the value of attribute logger.
35 36 37 |
# File 'lib/sniff.rb', line 35 def logger @logger end |
#options ⇒ Object
Returns the value of attribute options.
35 36 37 |
# File 'lib/sniff.rb', line 35 def @options end |
#project ⇒ Object
Returns the value of attribute project.
35 36 37 |
# File 'lib/sniff.rb', line 35 def project @project end |
#root ⇒ Object
Returns the value of attribute root.
35 36 37 |
# File 'lib/sniff.rb', line 35 def root @root end |
#test_support_path ⇒ Object
Returns the value of attribute test_support_path.
35 36 37 |
# File 'lib/sniff.rb', line 35 def test_support_path @test_support_path end |
Class Method Details
.init(local_root, options = {}) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/sniff.rb', line 27 def Sniff.init(local_root, = {}) sniff = new local_root, sniff.connect sniff.migrate! sniff.seed! sniff end |
.logger ⇒ Object
20 21 22 |
# File 'lib/sniff.rb', line 20 def Sniff.logger @logger ||= Logger.new nil end |
.logger=(val) ⇒ Object
23 24 25 |
# File 'lib/sniff.rb', line 23 def Sniff.logger=(val) @logger = val end |
.path(*rest) ⇒ Object
Get a path relative to sniff’s root
16 17 18 |
# File 'lib/sniff.rb', line 16 def Sniff.path(*rest) File.join(root, *rest) end |
.root ⇒ Object
Sniff’s root directory (the gem’s location on the filesystem)
11 12 13 |
# File 'lib/sniff.rb', line 11 def Sniff.root File.join(File.dirname(__FILE__), '..') end |
Instance Method Details
#connect ⇒ Object
Connect to the database and set up an ActiveRecord logger
84 85 86 87 |
# File 'lib/sniff.rb', line 84 def connect ActiveRecord::Base.logger = Sniff.logger Earth.connect end |
#emitter_class ⇒ Object
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/sniff.rb', line 89 def emitter_class return @emitter_class unless @emitter_class.nil? record_class_path = Dir.glob(File.join(test_support_path, '*_record.rb')).first if record_class_path require record_class_path record_class = File.read(record_class_path) klass = record_class.scan(/class ([^\s]*Record)/).flatten.first @emitter_class = klass.constantize end end |
#init_cucumber ⇒ Object
68 69 70 71 72 73 |
# File 'lib/sniff.rb', line 68 def init_cucumber require 'cucumber' require 'cucumber/formatter/unicode' # Remove this line if you don't want Cucumber Unicode support cukes = Dir.glob File.join(File.dirname(__FILE__), 'test_support', 'cucumber', '**', '*.rb') cukes.each { |support_file| require support_file } end |
#load_supporting_libs ⇒ Object
108 109 110 111 112 113 114 115 116 |
# File 'lib/sniff.rb', line 108 def load_supporting_libs require project $:.unshift File.join(root, 'lib') Dir[File.join(root, 'lib', 'test_support', '*.rb')].each do |lib| log "Loading #{lib}" require lib end end |
#migrate! ⇒ Object
100 101 102 |
# File 'lib/sniff.rb', line 100 def migrate! emitter_class.auto_upgrade! if emitter_class end |
#seed! ⇒ Object
104 105 106 |
# File 'lib/sniff.rb', line 104 def seed! Fixture.load_fixtures fixtures_path end |