guard-jasmine-headless-webkit 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -8,3 +8,4 @@ gem 'mocha'
8
8
  gem 'rake', '0.8.7'
9
9
  gem 'growl'
10
10
  gem 'fakefs', :require => nil
11
+ gem 'jasmine-headless-webkit', :path => '../jasmine-headless-webkit'
data/Guardfile CHANGED
@@ -1,7 +1,7 @@
1
1
  # A sample Guardfile
2
2
  # More info at https://github.com/guard/guard#readme
3
3
 
4
- guard 'rspec', :version => 2 do
4
+ guard 'rspec', :cli => '-c', :version => 2 do
5
5
  watch(%r{^spec/.+_spec\.rb})
6
6
  watch(%r{^lib/(.+)\.rb}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
7
  watch('spec/spec_helper.rb') { "spec" }
data/README.md CHANGED
@@ -15,9 +15,28 @@ home folder's `.jasmine-headless-webkit` file.
15
15
  ## `guard` options
16
16
 
17
17
  * `:all_on_start => false` to not run everything when starting, just like `guard-rspec`.
18
- * `:run_before => "<command to run>` to run a command before running specs. If the command fails, the test run stops.
19
- * `:jammit => true` to run `jammit -f 2>/dev/null` before the tests for the current file change are run.
20
- * `:valid_extensions => %w{` to run `jammit -f 2>/dev/null` before the tests for the current file change are run.
18
+ * `:run_before => "<command to run>"` to run a command before running specs. If the command fails, the test run stops.
19
+ * `:valid_extensions => %w{js coffee}` to only trigger `run_on_change` events for files with these extensions. Forces Guard to re-run all tests when any other matched file changes.
20
+
21
+ ## Using with Rails 3.1 and the Asset Pipeline and/or Jammit
22
+
23
+ Use [`guard-rails-assets`](https://github.com/dnagir/guard-rails-assets) chained in before `guard-jasmine-headless-webkit` to precompile your application
24
+ code for testing:
25
+
26
+ guard 'rails-assets' do
27
+ watch(%r{^app/assets/javascripts/.*})
28
+ end
29
+
30
+ guard 'jasmine-headless-webkit' do
31
+ watch(%r{^public/assets/.*\.js})
32
+ ... specs ...
33
+ end
34
+
35
+ Do the same for Jammit, using [`guard-jammit`](http://github.com/guard/guard-jammit).
36
+
37
+ ### `guard-jammit` and Jammit >= 0.6.0
38
+
39
+ Jammit >= 0.6.0 changed how it determines the Rails environment. Use [my fork of `guard-jammit`](http://github.com/johnbintz/guard-jammit) until it's fixed upstream.
21
40
 
22
41
  ## What's the deal with `newest_js_file`?
23
42
 
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
1
  require 'bundler'
2
2
  Bundler::GemHelper.install_tasks
3
3
 
4
+ include Rake::DSL if defined?(Rake::DSL)
5
+
4
6
  desc 'Push everywhere!'
5
7
  task :push_everywhere do
6
8
  system %{git push origin master}
@@ -19,6 +19,6 @@ Gem::Specification.new do |s|
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
21
 
22
- s.add_dependency 'guard', '>= 0.2.2'
23
- s.add_dependency 'jasmine-headless-webkit', '>= 0.2.2'
22
+ s.add_dependency 'guard', '>= 0.4.0'
23
+ s.add_dependency 'jasmine-headless-webkit', '>= 0.3.0'
24
24
  end
@@ -1,6 +1,7 @@
1
1
  require 'guard'
2
2
  require 'guard/guard'
3
3
  require 'guard/jasmine-headless-webkit/runner'
4
+ require 'coffee-script'
4
5
 
5
6
  module Guard
6
7
  class JasmineHeadlessWebkit < Guard
@@ -21,26 +22,32 @@ module Guard
21
22
  end
22
23
 
23
24
  def run_all
24
- JasmineHeadlessWebkitRunner.run if run_before and run_jammit
25
- @ran_jammit = false
25
+ run_something_and_rescue do
26
+ UI.info "Guard::JasmineHeadlessWebkit running all specs..."
27
+ JasmineHeadlessWebkitRunner.run if run_all_things_before
28
+ @ran_before = false
29
+ end
26
30
  end
27
31
 
28
32
  def run_on_change(paths)
29
- paths = filter_paths(paths)
30
- @ran_jammit = false
31
- if run_before and run_jammit
32
- @ran_jammit = true
33
- do_run_all = true
34
- if !paths.empty?
35
- do_run_all = (JasmineHeadlessWebkitRunner.run(paths) == 0)
33
+ run_something_and_rescue do
34
+ paths = filter_paths(paths)
35
+ @ran_before = false
36
+ if run_all_things_before
37
+ @ran_before = true
38
+ if !paths.empty?
39
+ UI.info "Guard::JasmineHeadlessWebkit running the following: #{paths.join(' ')}"
40
+ JasmineHeadlessWebkitRunner.run(paths)
41
+ else
42
+ run_all
43
+ end
36
44
  end
37
- run_all if do_run_all
38
45
  end
39
46
  end
40
47
 
41
48
  private
42
49
  def filter_paths(paths)
43
- paths.find_all { |path| File.extname(path)[valid_extensions] }
50
+ paths.find_all { |path| File.extname(path)[valid_extensions] }.uniq
44
51
  end
45
52
 
46
53
  def valid_extensions
@@ -48,27 +55,36 @@ module Guard
48
55
  end
49
56
 
50
57
  def run_before
51
- if @options[:run_before]
52
- run_program(@options[:run_before])
53
- else
54
- true
55
- end
58
+ run_a_thing_before(:run_before, @options[:run_before])
56
59
  end
57
60
 
58
- def run_jammit
59
- if @options[:jammit] && !@ran_jammit
60
- run_program("Jammit", %{jammit -f 2>/dev/null})
61
+ def run_a_thing_before(option, *args)
62
+ if @options[option] && !@ran_before
63
+ run_program(*args)
61
64
  else
62
65
  true
63
66
  end
64
67
  end
65
68
 
69
+ def run_all_things_before
70
+ run_before
71
+ end
72
+
66
73
  def run_program(name, command = nil)
67
74
  command ||= name
68
75
  UI.info "Guard::JasmineHeadlessWebkit running #{name}..."
69
76
  system command
70
77
  $?.exitstatus == 0
71
78
  end
79
+
80
+ def run_something_and_rescue
81
+ yield
82
+ rescue ::CoffeeScript::CompilationError
83
+ rescue StandardError => e
84
+ puts e.message
85
+ puts e.backtrace.join("\n")
86
+ puts
87
+ end
72
88
  end
73
89
 
74
90
  class Dsl
@@ -1,4 +1,5 @@
1
1
  require 'guard/notifier'
2
+ require 'jasmine/headless/runner'
2
3
 
3
4
  module Guard
4
5
  class JasmineHeadlessWebkitRunner
@@ -7,7 +8,7 @@ module Guard
7
8
  file = Tempfile.new('guard-jasmine-headless-webkit')
8
9
  file.close
9
10
 
10
- system %{jasmine-headless-webkit --report #{file.path} -c #{paths.join(" ")}}
11
+ Jasmine::Headless::Runner.run(:report => file.path, :colors => true, :files => paths)
11
12
 
12
13
  notify(file.path)
13
14
  end
@@ -16,7 +17,7 @@ module Guard
16
17
  if (data = File.read(file).strip).empty?
17
18
  Notifier.notify('Spec runner interrupted!', :title => 'Jasmine results', :image => :failed)
18
19
  else
19
- total, fails, any_console, secs = File.read(file).strip.split('/')
20
+ total, fails, any_console, secs = data.lines.first.strip.split('/')
20
21
 
21
22
  Notifier.notify(message(total, fails, secs, any_console == "T"), :title => 'Jasmine results', :image => image(any_console == "T", fails))
22
23
  fails.to_i
@@ -1,5 +1,5 @@
1
1
  module Guard
2
2
  module JasmineHeadlessWebkitVersion
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -22,6 +22,16 @@ describe Guard::JasmineHeadlessWebkitRunner do
22
22
  end
23
23
  end
24
24
 
25
+ context 'with failures' do
26
+ let(:data) { "1/0/F/5\nThis||Is||A||Failure\n" }
27
+
28
+ it 'should notify with the right information' do
29
+ Guard::Notifier.expects(:notify).with("1 test, 0 failures, 5 secs.", { :title => 'Jasmine results', :image => :success })
30
+
31
+ Guard::JasmineHeadlessWebkitRunner.notify(file)
32
+ end
33
+ end
34
+
25
35
  context 'system run interrupted' do
26
36
  let(:data) { '' }
27
37
 
@@ -27,6 +27,15 @@ describe Guard::JasmineHeadlessWebkit do
27
27
  end
28
28
 
29
29
  describe '#run_on_change' do
30
+ context 'two files' do
31
+ it "should only run one" do
32
+ Guard::JasmineHeadlessWebkitRunner.expects(:run).with(%w{test.js}).returns(1)
33
+ guard.expects(:run_all).never
34
+
35
+ guard.run_on_change(%w{test.js test.js})
36
+ end
37
+ end
38
+
30
39
  context 'jhw call fails' do
31
40
  it "should not run all" do
32
41
  Guard::JasmineHeadlessWebkitRunner.expects(:run).returns(1)
@@ -36,10 +45,10 @@ describe Guard::JasmineHeadlessWebkit do
36
45
  end
37
46
  end
38
47
 
39
- context 'succeed, run all' do
48
+ context 'succeed, but still do not run all' do
40
49
  it "should run all" do
41
50
  Guard::JasmineHeadlessWebkitRunner.expects(:run).returns(0)
42
- guard.expects(:run_all).once
51
+ guard.expects(:run_all).never
43
52
 
44
53
  guard.run_on_change(%w{test.js})
45
54
  end
@@ -69,6 +78,7 @@ describe Guard::JasmineHeadlessWebkit do
69
78
  before do
70
79
  Guard::JasmineHeadlessWebkitRunner.expects(:run).never
71
80
  Guard::UI.expects(:info).with(regexp_matches(/false/))
81
+ Guard::UI.expects(:info).with(regexp_matches(/running all/))
72
82
  end
73
83
 
74
84
  let(:options) { { :run_before => 'false' } }
@@ -82,6 +92,7 @@ describe Guard::JasmineHeadlessWebkit do
82
92
  before do
83
93
  Guard::JasmineHeadlessWebkitRunner.expects(:run).once
84
94
  Guard::UI.expects(:info).with(regexp_matches(/true/))
95
+ Guard::UI.expects(:info).with(regexp_matches(/running all/))
85
96
  end
86
97
 
87
98
  let(:options) { { :run_before => 'true' } }
@@ -91,32 +102,4 @@ describe Guard::JasmineHeadlessWebkit do
91
102
  end
92
103
  end
93
104
  end
94
-
95
- describe 'run jammit first' do
96
- context 'run on run_all if called first' do
97
- before do
98
- guard.expects(:run_program).once.returns(true)
99
- Guard::JasmineHeadlessWebkitRunner.expects(:run).once
100
- end
101
-
102
- let(:options) { { :jammit => true } }
103
-
104
- it "should run jammit first" do
105
- guard.run_all
106
- end
107
- end
108
-
109
- context 'only run once if run_on_change is successful' do
110
- before do
111
- guard.expects(:run_program).once.returns(true)
112
- Guard::JasmineHeadlessWebkitRunner.expects(:run).twice.returns(0)
113
- end
114
-
115
- let(:options) { { :jammit => true } }
116
-
117
- it "should run jammit only once" do
118
- guard.run_on_change(%w{path.js})
119
- end
120
- end
121
- end
122
105
  end
metadata CHANGED
@@ -1,50 +1,46 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: guard-jasmine-headless-webkit
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
4
5
  prerelease:
5
- version: 0.1.0
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - John Bintz
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-06-07 00:00:00 -04:00
12
+ date: 2011-08-05 00:00:00.000000000 -04:00
14
13
  default_executable:
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
17
16
  name: guard
18
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: &2166408320 !ruby/object:Gem::Requirement
19
18
  none: false
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: 0.2.2
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: 0.4.0
24
23
  type: :runtime
25
24
  prerelease: false
26
- version_requirements: *id001
27
- - !ruby/object:Gem::Dependency
25
+ version_requirements: *2166408320
26
+ - !ruby/object:Gem::Dependency
28
27
  name: jasmine-headless-webkit
29
- requirement: &id002 !ruby/object:Gem::Requirement
28
+ requirement: &2166407820 !ruby/object:Gem::Requirement
30
29
  none: false
31
- requirements:
32
- - - ">="
33
- - !ruby/object:Gem::Version
34
- version: 0.2.2
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: 0.3.0
35
34
  type: :runtime
36
35
  prerelease: false
37
- version_requirements: *id002
36
+ version_requirements: *2166407820
38
37
  description: Run jasmine-headless-webkit using guard
39
- email:
38
+ email:
40
39
  - john@coswellproductions.com
41
40
  executables: []
42
-
43
41
  extensions: []
44
-
45
42
  extra_rdoc_files: []
46
-
47
- files:
43
+ files:
48
44
  - .gitignore
49
45
  - Gemfile
50
46
  - Guardfile
@@ -59,40 +55,31 @@ files:
59
55
  - spec/lib/guard/jasmine-headless-webkit_spec.rb
60
56
  - spec/spec_helper.rb
61
57
  has_rdoc: true
62
- homepage: ""
58
+ homepage: ''
63
59
  licenses: []
64
-
65
60
  post_install_message:
66
61
  rdoc_options: []
67
-
68
- require_paths:
62
+ require_paths:
69
63
  - lib
70
- required_ruby_version: !ruby/object:Gem::Requirement
64
+ required_ruby_version: !ruby/object:Gem::Requirement
71
65
  none: false
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- hash: -738405479392593179
76
- segments:
77
- - 0
78
- version: "0"
79
- required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
71
  none: false
81
- requirements:
82
- - - ">="
83
- - !ruby/object:Gem::Version
84
- hash: -738405479392593179
85
- segments:
86
- - 0
87
- version: "0"
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
88
76
  requirements: []
89
-
90
77
  rubyforge_project: guard-jasmine-headless-webkit
91
78
  rubygems_version: 1.6.2
92
79
  signing_key:
93
80
  specification_version: 3
94
81
  summary: Run jasmine-headless-webkit using guard
95
- test_files:
82
+ test_files:
96
83
  - spec/lib/guard/jasmine-headless-webkit/runner_spec.rb
97
84
  - spec/lib/guard/jasmine-headless-webkit_spec.rb
98
85
  - spec/spec_helper.rb