guard-elixir 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/.travis.yml +10 -0
- data/Gemfile +4 -0
- data/Guardfile +5 -0
- data/LICENSE.txt +22 -0
- data/README.md +64 -0
- data/Rakefile +48 -0
- data/guard-elixir.gemspec +28 -0
- data/lib/guard/elixir.rb +90 -0
- data/lib/guard/elixir/templates/Guardfile +5 -0
- data/lib/guard/elixir/version.rb +5 -0
- data/spec/lib/guard/elixir_spec.rb +65 -0
- data/spec/spec_helper.rb +2 -0
- data/test/test_helper.exs +1 -0
- metadata +143 -0
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Patrick Wyatt
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# Guard::Elixir
|
2
|
+
[](https://travis-ci.org/webcoyote/guard-elixir)
|
3
|
+
|
4
|
+
Guard::Elixir is a [Guard](https://github.com/guard/guard) plugin that automatically runs tests for the [Elixir](http://elixir-lang.org/) language using "mix test".
|
5
|
+
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
The simplest way to install Guard::Elixir is to use [Bundler](http://gembundler.com/).
|
10
|
+
|
11
|
+
Add Guard::Elixir to your `Gemfile`:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
group :development do
|
15
|
+
gem 'guard-elixir', :git => 'git://github.com/webcoyote/guard-elixir'
|
16
|
+
end
|
17
|
+
```
|
18
|
+
|
19
|
+
and install it by running Bundler:
|
20
|
+
|
21
|
+
```bash
|
22
|
+
$ bundle
|
23
|
+
```
|
24
|
+
|
25
|
+
Add guard definition to your Guardfile by running the following command:
|
26
|
+
|
27
|
+
```bash
|
28
|
+
guard init elixir
|
29
|
+
```
|
30
|
+
|
31
|
+
Run guard to automatically run your Elixir tests
|
32
|
+
|
33
|
+
```bash
|
34
|
+
bundle exec guard start
|
35
|
+
```
|
36
|
+
|
37
|
+
|
38
|
+
## Usage
|
39
|
+
|
40
|
+
Please read [Guard usage doc](http://github.com/guard/guard#readme)
|
41
|
+
|
42
|
+
|
43
|
+
### Standard Guardfile when using Guard::Elixir
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
guard :elixir do
|
47
|
+
watch(%r{^test/(.*)_test\.exs})
|
48
|
+
watch(%r{^lib/(.+)\.ex$}) { |m| "test/#{m[1]}_test.exs" }
|
49
|
+
watch(%r{^test/test_helper.exs$}) { "test" }
|
50
|
+
end
|
51
|
+
```
|
52
|
+
|
53
|
+
## Contributing
|
54
|
+
|
55
|
+
1. Fork it
|
56
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
57
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
58
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
59
|
+
5. Create new Pull Request
|
60
|
+
|
61
|
+
|
62
|
+
# Author
|
63
|
+
|
64
|
+
Author:: [Patrick Wyatt](https://github.com/webcoyote) (pat@codeofhonor.com)
|
data/Rakefile
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
RSpec::Core::RakeTask.new(:spec)
|
6
|
+
task :default => :spec
|
7
|
+
|
8
|
+
require 'rbconfig'
|
9
|
+
namespace(:spec) do
|
10
|
+
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw/i
|
11
|
+
desc "Run all specs on multiple ruby versions (requires pik)"
|
12
|
+
task(:portability) do
|
13
|
+
%w[193 200].each do |version|
|
14
|
+
system "cmd /c echo -----------#{version}------------ & " +
|
15
|
+
"pik use #{version} & " +
|
16
|
+
"bundle install & " +
|
17
|
+
"bundle exec rspec spec"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
else
|
21
|
+
desc "Run all specs on multiple ruby versions (requires rvm)"
|
22
|
+
task(:portability) do
|
23
|
+
travis_config_file = File.expand_path("../.travis.yml", __FILE__)
|
24
|
+
begin
|
25
|
+
travis_options ||= YAML::load_file(travis_config_file)
|
26
|
+
rescue => ex
|
27
|
+
puts "Travis config file '#{travis_config_file}' could not be found: #{ex.message}"
|
28
|
+
return
|
29
|
+
end
|
30
|
+
|
31
|
+
travis_options['rvm'].each do |version|
|
32
|
+
system <<-BASH
|
33
|
+
bash -c 'source ~/.rvm/scripts/rvm;
|
34
|
+
rvm #{version};
|
35
|
+
ruby_version_string_size=`ruby -v | wc -m`
|
36
|
+
echo;
|
37
|
+
for ((c=1; c<$ruby_version_string_size; c++)); do echo -n "="; done
|
38
|
+
echo;
|
39
|
+
echo "`ruby -v`";
|
40
|
+
for ((c=1; c<$ruby_version_string_size; c++)); do echo -n "="; done
|
41
|
+
echo;
|
42
|
+
bundle install;
|
43
|
+
bundle exec rspec spec -f doc 2>&1;'
|
44
|
+
BASH
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'guard/elixir/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "guard-elixir"
|
8
|
+
spec.version = Guard::ElixirVersion::VERSION
|
9
|
+
spec.authors = ["Patrick Wyatt"]
|
10
|
+
spec.email = ["pat@codeofhonor.com"]
|
11
|
+
spec.description = "Guard::Elixir automatically runs Elixir 'mix' tests"
|
12
|
+
spec.summary = "Guard gem for Elixir language"
|
13
|
+
spec.homepage = "https://github.com/webcoyote/guard-elixir"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
spec.required_ruby_version = ">= 1.9.3"
|
21
|
+
|
22
|
+
spec.add_dependency 'guard'
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
spec.add_development_dependency 'rspec'
|
27
|
+
spec.add_development_dependency 'guard-rspec'
|
28
|
+
end
|
data/lib/guard/elixir.rb
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'guard'
|
2
|
+
require 'guard/guard'
|
3
|
+
require 'guard/watcher'
|
4
|
+
require 'guard/notifier'
|
5
|
+
|
6
|
+
module Guard
|
7
|
+
class Elixir < Guard
|
8
|
+
def initialize(watchers=[], options={})
|
9
|
+
super
|
10
|
+
@options = {
|
11
|
+
all_on_start: true,
|
12
|
+
dry_run: false,
|
13
|
+
}.update(options)
|
14
|
+
end
|
15
|
+
|
16
|
+
def start
|
17
|
+
run_all if @options[:all_on_start]
|
18
|
+
end
|
19
|
+
|
20
|
+
def run_all
|
21
|
+
files = Dir.glob("**/*.*")
|
22
|
+
targets = Watcher.match_files(self, files)
|
23
|
+
run_on_change targets
|
24
|
+
end
|
25
|
+
|
26
|
+
# Called on file(s) modifications
|
27
|
+
def run_on_change(paths)
|
28
|
+
if @options[:dry_run]
|
29
|
+
paths.each { |path| UI.info "Dry run: #{path}" }
|
30
|
+
return
|
31
|
+
end
|
32
|
+
|
33
|
+
total = 0
|
34
|
+
failures = 0
|
35
|
+
duration = 0
|
36
|
+
run_command("mix test #{paths.join(' ')}") do |line|
|
37
|
+
puts line
|
38
|
+
if /Finished in ([0-9.]+) seconds/.match(line)
|
39
|
+
duration = Regexp::last_match[1]
|
40
|
+
elsif /([0-9]+) tests, ([0-9]+) failures/.match(line)
|
41
|
+
total = Regexp::last_match[1].to_i
|
42
|
+
failures = Regexp::last_match[2].to_i
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
Notifier.notify(
|
47
|
+
guard_message(total, failures, duration),
|
48
|
+
:title => "Elixir results",
|
49
|
+
:image => guard_image(failures),
|
50
|
+
:priority => guard_priority(failures)
|
51
|
+
)
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def run_command(cmd)
|
57
|
+
UI.debug "+ #{cmd}"
|
58
|
+
IO.popen(cmd, :err => [:child, :out]).each do |line|
|
59
|
+
if block_given?
|
60
|
+
yield line
|
61
|
+
else
|
62
|
+
puts line
|
63
|
+
end
|
64
|
+
end
|
65
|
+
Process.wait
|
66
|
+
$?.success?
|
67
|
+
end
|
68
|
+
|
69
|
+
def guard_image(failures)
|
70
|
+
if failures > 0
|
71
|
+
:failed
|
72
|
+
else
|
73
|
+
:success
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def guard_priority(failures)
|
78
|
+
if failures > 0
|
79
|
+
2
|
80
|
+
else
|
81
|
+
-2
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def guard_message(total, failures, duration)
|
86
|
+
"#{total} tests, #{failures} failures\nin #{duration} seconds"
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require "guard/watcher"
|
3
|
+
require "guard/ui"
|
4
|
+
|
5
|
+
describe "Guard-Elixir" do
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
@subject = Guard::Elixir.new
|
9
|
+
@paths = [ "foo.ex", "dir1/dir2/dir3/bar.ex" ]
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "initialize" do
|
13
|
+
it "should start with default options" do
|
14
|
+
@subject.options[:all_on_start].should be true
|
15
|
+
@subject.options[:dry_run].should be false
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should be possible to overwrite the default options" do
|
19
|
+
@subject = Guard::Elixir.new([],{
|
20
|
+
all_on_start: false,
|
21
|
+
dry_run: true
|
22
|
+
})
|
23
|
+
@subject.options[:all_on_start].should be false
|
24
|
+
@subject.options[:dry_run].should be true
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "start" do
|
29
|
+
describe "all_on_start" do
|
30
|
+
it "should run all tests if all_on_start is true" do
|
31
|
+
@subject = Guard::Elixir.new([],{ dry_run: true })
|
32
|
+
@subject.should_receive(:run_all)
|
33
|
+
@subject.start
|
34
|
+
end
|
35
|
+
it "should not run all tests on start if all_on_start is false" do
|
36
|
+
@subject = Guard::Elixir.new([],{ all_on_start: false, dry_run: true })
|
37
|
+
@subject.should_not_receive(:run_all)
|
38
|
+
@subject.start
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "run_on_change" do
|
44
|
+
describe "dry run" do
|
45
|
+
it "should not perform a conversion on a dry run" do
|
46
|
+
@subject = Guard::Elixir.new([],{ dry_run: true })
|
47
|
+
Kernel.should_not_receive(:exec)
|
48
|
+
Guard::UI.should_receive(:info).exactly(@paths.count).times
|
49
|
+
@subject.run_on_change(@paths)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "run_all" do
|
55
|
+
it "should call run_on_change for all matching paths" do
|
56
|
+
@subject = Guard::Elixir.new([],{ dry_run: true })
|
57
|
+
Dir.should_receive(:glob).with("**/*.*").and_return(@paths)
|
58
|
+
Guard::Watcher.should_receive(:match_files).with(@subject, @paths).and_return(@paths)
|
59
|
+
@subject.should_receive(:run_on_change).with(@paths)
|
60
|
+
@subject.run_all
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ExUnit.start
|
metadata
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: guard-elixir
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Patrick Wyatt
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-08-24 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: guard
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: bundler
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rspec
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: guard-rspec
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
description: Guard::Elixir automatically runs Elixir 'mix' tests
|
95
|
+
email:
|
96
|
+
- pat@codeofhonor.com
|
97
|
+
executables: []
|
98
|
+
extensions: []
|
99
|
+
extra_rdoc_files: []
|
100
|
+
files:
|
101
|
+
- .gitignore
|
102
|
+
- .travis.yml
|
103
|
+
- Gemfile
|
104
|
+
- Guardfile
|
105
|
+
- LICENSE.txt
|
106
|
+
- README.md
|
107
|
+
- Rakefile
|
108
|
+
- guard-elixir.gemspec
|
109
|
+
- lib/guard/elixir.rb
|
110
|
+
- lib/guard/elixir/templates/Guardfile
|
111
|
+
- lib/guard/elixir/version.rb
|
112
|
+
- spec/lib/guard/elixir_spec.rb
|
113
|
+
- spec/spec_helper.rb
|
114
|
+
- test/test_helper.exs
|
115
|
+
homepage: https://github.com/webcoyote/guard-elixir
|
116
|
+
licenses:
|
117
|
+
- MIT
|
118
|
+
post_install_message:
|
119
|
+
rdoc_options: []
|
120
|
+
require_paths:
|
121
|
+
- lib
|
122
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
+
none: false
|
124
|
+
requirements:
|
125
|
+
- - ! '>='
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: 1.9.3
|
128
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
requirements: []
|
135
|
+
rubyforge_project:
|
136
|
+
rubygems_version: 1.8.23
|
137
|
+
signing_key:
|
138
|
+
specification_version: 3
|
139
|
+
summary: Guard gem for Elixir language
|
140
|
+
test_files:
|
141
|
+
- spec/lib/guard/elixir_spec.rb
|
142
|
+
- spec/spec_helper.rb
|
143
|
+
- test/test_helper.exs
|