Module: JasmineMixin

Included in:
Autotest::Jasmine, Autotest::JasmineRspec2
Defined in:
lib/autotest/jasmine_mixin.rb

Constant Summary collapse

JASMINE_PROGRAM =
File.expand_path('../../../bin/jasmine-headless-webkit', __FILE__)
JAVASCRIPT_EXTENSIONS =
%w{js coffee}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#is_jasmine_runningObject

Returns the value of attribute is_jasmine_running.



10
11
12
# File 'lib/autotest/jasmine_mixin.rb', line 10

def is_jasmine_running
  @is_jasmine_running
end

#jasmine_ran_onceObject

Returns the value of attribute jasmine_ran_once.



10
11
12
# File 'lib/autotest/jasmine_mixin.rb', line 10

def jasmine_ran_once
  @jasmine_ran_once
end

#jasmine_to_runObject

Returns the value of attribute jasmine_to_run.



10
11
12
# File 'lib/autotest/jasmine_mixin.rb', line 10

def jasmine_to_run
  @jasmine_to_run
end

Class Method Details

.included(klass) ⇒ Object



6
7
8
# File 'lib/autotest/jasmine_mixin.rb', line 6

def self.included(klass)
  klass::ALL_HOOKS << [ :run_jasmine, :ran_jasmine ]
end

Instance Method Details

#add_javascript_extensions(*extensions) ⇒ Object



108
109
110
# File 'lib/autotest/jasmine_mixin.rb', line 108

def add_javascript_extensions(*extensions)
  self.class::JAVASCRIPT_EXTENSIONS << extensions
end

#all_jasmine_goodObject



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

def all_jasmine_good
  self.jasmine_to_run == :none
  self.files_to_test = new_hash_of_arrays
end

#find_filesObject



74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/autotest/jasmine_mixin.rb', line 74

def find_files
  Hash[super.find_all { |file, mtime|
    is_js = (file[%r{\.(#{JAVASCRIPT_EXTENSIONS.join('|')})$}] != nil)

    case self.is_jasmine_running
    when :all
      true
    when :no
      !is_js
    when :yes
      is_js
    end
  }]
end

#get_to_greenObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/autotest/jasmine_mixin.rb', line 18

def get_to_green
  begin
    reset_jasmine(:no)
    super if find_files_to_test

    reset_jasmine(:yes)
    self.last_mtime = Time.at(0) if !options[:no_full_after_start] && !jasmine_ran_once
    run_jasmine if find_files_to_test

    self.is_jasmine_running = :all
    wait_for_changes unless all_jasmine_good
  end until all_jasmine_good

  reset_jasmine(:all)
end

#initializeObject



12
13
14
15
16
# File 'lib/autotest/jasmine_mixin.rb', line 12

def initialize
  super()
  setup_jasmine_project_mappings
  jasmine_ran_once = false
end

#make_jasmine_cmdObject



89
90
91
92
# File 'lib/autotest/jasmine_mixin.rb', line 89

def make_jasmine_cmd
  self.files_to_test.empty? ? '' :
    %{#{JASMINE_PROGRAM} #{self.files_to_test.keys.collect { |key| %{'#{key}'} }.join(' ')}}.tap { |o| p o }
end

#rerun_all_testsObject



34
35
36
37
38
39
40
41
42
# File 'lib/autotest/jasmine_mixin.rb', line 34

def rerun_all_tests
  reset_jasmine(:no)
  super

  reset_jasmine(:yes)
  run_jasmine

  reset_jasmine(:all)
end

#reset_jasmine(method) ⇒ Object



44
45
46
47
# File 'lib/autotest/jasmine_mixin.rb', line 44

def reset_jasmine(method)
  self.files_to_test = new_hash_of_arrays
  self.is_jasmine_running = method
end

#run_jasmineObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/autotest/jasmine_mixin.rb', line 49

def run_jasmine
  hook :run_jasmine

  self.jasmine_to_run = :all

  if mtime = find_files_to_test
    self.last_mtime = mtime
  end

  begin
    system make_jasmine_cmd

    self.jasmine_to_run = ($?.exitstatus == 0) ? :none : :all
  end

  hook :ran_jasmine

  jasmine_ran_once = true
end

#setup_jasmine_project_mappingsObject



94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/autotest/jasmine_mixin.rb', line 94

def setup_jasmine_project_mappings
  add_mapping(%r{spec/javascripts/.*_spec\.(js|coffee)}) { |filename, _|
    filename
  }

  add_mapping(%r{public/javascripts/(.*)\.js}) { |_, m|
    files_matching(%r{spec/javascripts/#{m[1]}_spec\..*$})
  }

  add_mapping(%r{app/coffeescripts/(.*)\.coffee}) { |_, m|
    files_matching(%r{spec/javascripts/#{m[1]}_spec\..*$})
  }
end