class Guard::JasmineRails

Constants

DEFAULTS
LOG_PREFIX
NOTIFICATION_TITLE

Public Class Methods

new(options = {}) click to toggle source
Calls superclass method
# File lib/guard/jasmine-rails.rb, line 13
def initialize(options = {})
  super DEFAULTS.merge(options)
end

Public Instance Methods

run_all() click to toggle source
# File lib/guard/jasmine-rails.rb, line 22
def run_all
  spec_filter = nil
  run spec_filter
end
run_on_changes(paths) click to toggle source

run jasmine specs for only the changed files if the changed file does not contain a jasmine describe block, re-run the entire jasmine test suite

# File lib/guard/jasmine-rails.rb, line 30
def run_on_changes(paths)
  spec_filters = paths.collect {|path| spec_description(path) }.uniq
  spec_filters = [nil] if spec_filters.include?(nil)
  spec_filters.each do |spec_filter|
    run spec_filter
  end
end
start() click to toggle source
# File lib/guard/jasmine-rails.rb, line 17
def start
  log 'is now running'
  run_all if options[:all_on_start]
end

Private Instance Methods

log(message, level = :info) click to toggle source
# File lib/guard/jasmine-rails.rb, line 64
def log(message, level = :info)
  UI.send(level, [LOG_PREFIX, message].join(' '))
end
notify(message, type = :success) click to toggle source
# File lib/guard/jasmine-rails.rb, line 68
def notify(message, type = :success)
  priority = {
    failed:   2,
    success: -2
  }[type]
  ::Guard::Notifier.notify(message, title: NOTIFICATION_TITLE , image: type, priority: priority)
end
run(spec_filter = nil) click to toggle source
# File lib/guard/jasmine-rails.rb, line 46
def run(spec_filter = nil)
  message = 'Running Jasmine specs'
  message += " with filter: #{spec_filter}" if spec_filter
  log message

  command = "bundle exec rake spec:javascript RAILS_ENV=test"
  command += " SPEC=#{spec_filter}" if spec_filter
  log "Running: #{command}", :debug
  success = system(command)
  if success
    log 'No failures detected'
    notify 'All specs passed.', :success
  else
    log "Error running specs", :error
    notify 'Error running specs.', :failed
  end
end
spec_description(path) click to toggle source

parse the outermost describe block from a Jasmine spec file returns nil if no describe block is found

# File lib/guard/jasmine-rails.rb, line 42
def spec_description(path)
  File.read(path).scan(/describe.+?['"]([^'"]+)/).flatten.first
end