checker 0.0.5 → 0.0.6

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.
Files changed (41) hide show
  1. data/.travis.yml +12 -0
  2. data/CHANGELOG +7 -0
  3. data/Gemfile +5 -0
  4. data/Gemfile.lock +22 -0
  5. data/README.md +11 -4
  6. data/Rakefile +3 -1
  7. data/checker.gemspec +7 -4
  8. data/lib/checker.rb +4 -0
  9. data/lib/checker/cli.rb +9 -4
  10. data/lib/checker/modules/base.rb +87 -46
  11. data/lib/checker/modules/coffeescript.rb +1 -1
  12. data/lib/checker/modules/haml.rb +4 -0
  13. data/lib/checker/modules/javascript.rb +3 -6
  14. data/lib/checker/modules/pry.rb +2 -21
  15. data/lib/checker/modules/ruby.rb +1 -1
  16. data/lib/checker/modules/sass.rb +2 -2
  17. data/lib/checker/modules/slim.rb +21 -0
  18. data/lib/checker/modules/yaml.rb +21 -0
  19. data/lib/checker/version.rb +3 -0
  20. data/spec/checker/cli_spec.rb +1 -8
  21. data/spec/checker/fixtures/pry/with_both.rb +4 -0
  22. data/spec/checker/fixtures/pry/with_pry.rb +3 -0
  23. data/spec/checker/fixtures/pry/with_pry_remote.rb +3 -0
  24. data/spec/checker/fixtures/pry/without_pry.rb +2 -0
  25. data/spec/checker/fixtures/ruby/1.8/bad.rb +3 -0
  26. data/spec/checker/fixtures/ruby/1.8/bad2.rb +2 -0
  27. data/spec/checker/fixtures/ruby/1.8/good.rb +3 -0
  28. data/spec/checker/fixtures/ruby/1.9/bad.rb +2 -0
  29. data/spec/checker/fixtures/ruby/1.9/good.rb +3 -0
  30. data/spec/checker/fixtures/yaml/bad.yaml +18 -0
  31. data/spec/checker/fixtures/yaml/good.yaml +18 -0
  32. data/spec/checker/modules/coffeescript_spec.rb +16 -0
  33. data/spec/checker/modules/haml_spec.rb +18 -0
  34. data/spec/checker/modules/javascript_spec.rb +18 -0
  35. data/spec/checker/modules/pry_spec.rb +35 -0
  36. data/spec/checker/modules/ruby_spec.rb +41 -3
  37. data/spec/checker/modules/sass_spec.rb +21 -0
  38. data/spec/checker/modules/slim_spec.rb +18 -0
  39. data/spec/checker/modules/yaml_spec.rb +27 -0
  40. data/spec/spec_helper.rb +23 -1
  41. metadata +39 -7
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - ree
7
+ notifications:
8
+ email:
9
+ recipients:
10
+ - jacek.jakubik@netguru.pl
11
+ - tomasz.pewinski@netguru.pl
12
+
data/CHANGELOG CHANGED
@@ -1,3 +1,10 @@
1
+ === version 0.0.6 (released 2012-08-28)
2
+
3
+ * better support for rvm users
4
+ * adding slim support (thanks to Filip Skokan)
5
+ * better check for files which are staged and modified
6
+ * cleanups, speed and refactor
7
+
1
8
  === version 0.0.5 (released 2012-07-09)
2
9
 
3
10
  * depencendy message - if executable not found,
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'rake'
4
+ gem 'rspec'
5
+ gem 'colorize'
@@ -0,0 +1,22 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ colorize (0.5.8)
5
+ diff-lcs (1.1.3)
6
+ rake (0.9.2.2)
7
+ rspec (2.11.0)
8
+ rspec-core (~> 2.11.0)
9
+ rspec-expectations (~> 2.11.0)
10
+ rspec-mocks (~> 2.11.0)
11
+ rspec-core (2.11.0)
12
+ rspec-expectations (2.11.1)
13
+ diff-lcs (~> 1.1.3)
14
+ rspec-mocks (2.11.1)
15
+
16
+ PLATFORMS
17
+ ruby
18
+
19
+ DEPENDENCIES
20
+ colorize
21
+ rake
22
+ rspec
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Checker
1
+ # Checker [![Build Status](https://secure.travis-ci.org/netguru/checker.png?branch=master)](http://travis-ci.org/netguru/checker)
2
2
 
3
3
  A collection of modules for which every is designed to check syntax in files to be commited via git.
4
4
 
@@ -34,6 +34,13 @@ fi
34
34
  echo ":checkered_flag:" >> $1
35
35
  ```
36
36
 
37
+ you can also prepend the flag to the first line of commit message, by changing last line with:
38
+
39
+ ``` bash
40
+ text=`echo -n ':checkered_flag: '; cat $1`
41
+ echo $text > $1
42
+ ```
43
+
37
44
  #### pre-commit hook
38
45
  To just check your source code every time you commit, add to your `.git/hooks/pre-commit` line:
39
46
 
@@ -68,12 +75,12 @@ To check only specific filetypes on commit, use `git config` :
68
75
  git config checker.check 'ruby, haml, coffeescript'
69
76
  ```
70
77
 
71
- Available options are: ruby, haml, pry, coffeescript, sass
78
+ Available options are: ruby, haml, pry, coffeescript, sass, slim
72
79
 
73
80
  ### Dependencies
74
81
 
75
82
  For various modules to work you may need to install additional dependencies:
76
83
 
77
84
  * coffeescript - `npm install -g coffee-script` - see https://github.com/jashkenas/coffee-script/
78
- * javascript - `npm install -g jshint` - see https://github.com/jshint/node-jshint/#install
79
- * haml & sass - `gem install haml` `gem install sass`
85
+ * javascript - install jsl binary - see http://www.javascriptlint.com/download.htm
86
+ * haml & sass & slim - `gem install haml sass slim`
data/Rakefile CHANGED
@@ -1,2 +1,4 @@
1
1
  require 'rspec/core/rake_task'
2
- RSpec::Core::RakeTask.new(:spec)
2
+ RSpec::Core::RakeTask.new(:spec)
3
+
4
+ task :default => :spec
@@ -1,11 +1,14 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require File.expand_path('../lib/checker/version', __FILE__)
3
+
1
4
  Gem::Specification.new do |s|
2
5
  s.name = 'checker'
3
- s.version = '0.0.5'
4
- s.date = '2012-07-11'
6
+ s.version = Checker::VERSION
7
+ s.date = '2012-08-28'
5
8
  s.summary = "Syntax checker for various files"
6
9
  s.description = "A collection of modules which every is designed to check syntax for specific files."
7
- s.authors = ["Jacek Jakubik"]
8
- s.email = 'jacek.jakubik@netguru.pl'
10
+ s.authors = ["Jacek Jakubik", "Tomasz Pewiński"]
11
+ s.email = ['jacek.jakubik@netguru.pl', 'tomasz.pewinski@netguru.pl']
9
12
  s.files = `git ls-files`.split("\n")
10
13
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
11
14
  s.require_paths = ["lib"]
@@ -1,11 +1,15 @@
1
1
  require 'colorize'
2
+ require 'digest/md5'
2
3
 
3
4
  require 'checker/core_ext'
5
+ require 'checker/version'
4
6
 
5
7
  require "checker/modules/base"
6
8
  require "checker/modules/ruby"
7
9
  require "checker/modules/haml"
10
+ require "checker/modules/slim"
8
11
  require "checker/modules/pry"
9
12
  require "checker/modules/coffeescript"
10
13
  require "checker/modules/javascript"
11
14
  require "checker/modules/sass"
15
+ require "checker/modules/yaml"
@@ -21,13 +21,18 @@ module Checker
21
21
  exit 1
22
22
  end
23
23
 
24
- checked = []
24
+ module_instances = []
25
25
  files = modified_files
26
26
  modules.each do |mod|
27
27
  klass = "Checker::Modules::#{mod.downcase.capitalize}".constantize
28
- checked << klass.new(files.dup).check
28
+ module_instances << klass.new(files.dup)
29
29
  end
30
- exit (checked.all_true? ? 0 : 1)
30
+
31
+ files_checked = module_instances.map(&:files_to_check).flatten.uniq
32
+ puts "[ CHECKER #{Checker::VERSION} - #{files_checked.size} files ]".light_blue
33
+
34
+ results = module_instances.map(&:check)
35
+ exit (results.all_true? ? 0 : 1)
31
36
  end
32
37
 
33
38
  private
@@ -49,7 +54,7 @@ module Checker
49
54
  end
50
55
 
51
56
  def modified_files
52
- @modified_files ||= `git status --porcelain | egrep "^(A |M |R ).*" | awk ' { if ($3 == "->") print $4; else print $2 } '`.split
57
+ @modified_files ||= `git status --porcelain | egrep "^(A|M|R).*" | awk ' { if ($3 == "->") print $4; else print $2 } '`.split
53
58
  end
54
59
  end
55
60
  end
@@ -2,10 +2,9 @@ module Checker
2
2
  module Modules
3
3
  class Base < Struct.new(:files)
4
4
  def check
5
+ check_files_existing or return true
5
6
  print_module_header
6
- prepare_check
7
7
  check_executable or return true
8
- select_proper_files
9
8
  check_all_files
10
9
  valid?
11
10
  end
@@ -14,19 +13,30 @@ module Checker
14
13
  @results.all_true?
15
14
  end
16
15
 
16
+ def files_to_check
17
+ @files_to_check ||= begin
18
+ if self.class.extensions.any?
19
+ self.files.select { |f|
20
+ self.class.extensions.map { |ex| f.ends_with?(".#{ex}") }.any?
21
+ }
22
+ else
23
+ self.files
24
+ end
25
+ end
26
+ end
27
+
17
28
  private
18
29
 
19
30
  def print_module_header
20
- color "[ #{name} ]\n", :light_blue
31
+ color "[ #{name} - #{files_to_check.size} files ]\n", :light_blue
21
32
  end
22
33
 
23
34
  def dependency_message
24
35
  "Executable not found, skipping...\n"
25
36
  end
26
37
 
27
- def prepare_check
28
- @files_to_check = []
29
- @results = []
38
+ def check_files_existing
39
+ files_to_check.any?
30
40
  end
31
41
 
32
42
  def check_executable
@@ -42,21 +52,22 @@ module Checker
42
52
  true
43
53
  end
44
54
 
45
- def select_proper_files
46
- @files_to_check = self.files
47
- if self.class.extensions.any?
48
- @files_to_check = @files_to_check.select { |f|
49
- self.class.extensions.map { |ex| f.ends_with?(".#{ex}") }.any?
50
- }
55
+ def check_all_files
56
+ with_checker_cache do
57
+ @results = files_to_check.map do |file_name|
58
+ color " Checking #{file_name}...", :yellow
59
+ result = check_one_file(file_name)
60
+ show_status(result)
61
+ flush_and_forget_output(result)
62
+ result
63
+ end
51
64
  end
52
- @files_to_check
53
65
  end
54
66
 
55
- def check_all_files
56
- @results = @files_to_check.map do |file|
57
- color "Checking #{file}...", :yellow
58
- check_one(file)
59
- end
67
+ def check_one_file file_name
68
+ checksum = ::Digest::MD5.hexdigest(file_name)
69
+ checkout_file(file_name, checksum)
70
+ check_one(checkout_file_name(checksum))
60
71
  end
61
72
 
62
73
  def self.extensions *args
@@ -69,38 +80,47 @@ module Checker
69
80
  end
70
81
 
71
82
  def plain_command(cmd, options = {})
72
- exitstatus = system(cmd)
73
- show_output(exitstatus, options)
74
- exitstatus
83
+ cmd = parse_command(cmd, options)
84
+ execute(cmd)
75
85
  end
76
86
 
77
- def command(cmd, options = {})
78
- if options[:use_bundler] == true
79
- if use_bundler?
80
- cmd = "bundle exec #{cmd}"
81
- end
82
- end
87
+ def silent_command(cmd, options = {})
88
+ options = { :output => false }.merge(options)
89
+ cmd = parse_command(cmd, options)
90
+ execute(cmd)
91
+ end
83
92
 
84
- cmd = rvm_command(cmd) if use_rvm?
85
- cmd << " #{options[:append]}" if options[:append]
86
- exitstatus = execute(cmd)
87
- show_output(exitstatus, options)
88
- exitstatus
93
+ def flush_and_forget_output(success)
94
+ print @buffer.to_s unless success
95
+ @buffer = ""
89
96
  end
90
97
 
91
- def show_output(exitstatus, options)
92
- unless options[:show_output] == false
93
- if exitstatus
94
- puts " [OK]".green
95
- else
96
- puts " [FAIL]".red
97
- end
98
+ def show_status(success)
99
+ if success
100
+ puts " [OK]".green
101
+ else
102
+ puts " [FAIL]".red
98
103
  end
99
104
  end
100
105
 
101
-
102
106
  def execute(cmd)
103
- system(cmd)
107
+ io = IO.popen(cmd)
108
+ Process.wait(io.pid)
109
+ @buffer ||= ""
110
+ @buffer << io.read
111
+ success?
112
+ end
113
+
114
+ def success?
115
+ $? && $?.success?
116
+ end
117
+
118
+ def parse_command command, options
119
+ options = { :bundler => true, :output => true }.merge(options)
120
+ command = bundler_command(command) if use_bundler? && options[:bundler]
121
+ command = rvm_command(command) if use_rvm?
122
+ command << " > /dev/null" unless options[:output]
123
+ "#{command} 2>&1"
104
124
  end
105
125
 
106
126
  def color(str, color)
@@ -112,20 +132,41 @@ module Checker
112
132
  end
113
133
 
114
134
  def use_bundler?
115
- File.exists?("Gemfile.lock")
135
+ File.exists?("Gemfile.lock")
136
+ end
137
+
138
+ def bundler_command(command)
139
+ "bundle exec #{command}"
116
140
  end
117
141
 
118
142
  def use_rvm?
119
- File.exists?(".rvmrc") && File.exists?(rvm_shell)
143
+ File.exists?(rvm_shell)
144
+ end
145
+
146
+ def rvm_command(command)
147
+ rvm_version = ENV.fetch('RUBY_VERSION')
148
+ "#{rvm_shell} '#{rvm_version}' -c '#{command}'"
120
149
  end
121
150
 
122
151
  def rvm_shell
123
152
  File.join(ENV.fetch('rvm_path', ''), 'bin/rvm-shell')
124
153
  end
125
154
 
126
- def rvm_command(command)
127
- rvm_version = `echo $rvm_ruby_string`.chomp
128
- "#{rvm_shell} '#{rvm_version}' -c '#{command}'"
155
+ def with_checker_cache
156
+ begin
157
+ `mkdir .checker-cache`
158
+ yield if block_given?
159
+ ensure
160
+ `rm -rf .checker-cache > /dev/null 2>&1`
161
+ end
162
+ end
163
+
164
+ def checkout_file file_name, target
165
+ `git show :0:#{file_name} > #{checkout_file_name(target)} 2>/dev/null`
166
+ end
167
+
168
+ def checkout_file_name target
169
+ ".checker-cache/#{target}"
129
170
  end
130
171
  end
131
172
  end
@@ -8,7 +8,7 @@ module Checker
8
8
  end
9
9
 
10
10
  def check_for_executable
11
- command('coffee -v', :show_output => false, :append => ">> /dev/null 2>&1")
11
+ silent_command('coffee -v', :bundler => false)
12
12
  end
13
13
 
14
14
  def dependency_message
@@ -7,6 +7,10 @@ module Checker
7
7
  plain_command("haml --check #{file} >> /dev/null")
8
8
  end
9
9
 
10
+ def check_for_executable
11
+ silent_command("haml -v")
12
+ end
13
+
10
14
  def dependency_message
11
15
  str = "Executable not found\n"
12
16
  str << "Install haml from rubygems: 'gem install haml'\n"
@@ -8,7 +8,7 @@ module Checker
8
8
  end
9
9
 
10
10
  def check_for_executable
11
- command('jsl -help:conf', :show_output => false, :append => ">> /dev/null 2>&1")
11
+ silent_command('jsl -help:conf', :bundler => false)
12
12
  end
13
13
 
14
14
  def dependency_message
@@ -19,11 +19,8 @@ module Checker
19
19
  end
20
20
 
21
21
  # ignore exit status 1 - warnings
22
- def plain_command cmd, options={}
23
- system(cmd)
24
- exitstatus = $?.exitstatus == 0 || $?.exitstatus == 1
25
- show_output(exitstatus, options)
26
- exitstatus
22
+ def success?
23
+ $? && ($?.exitstatus == 0 || $?.exitstatus == 1)
27
24
  end
28
25
  end
29
26
  end
@@ -8,30 +8,11 @@ module Checker
8
8
  end
9
9
 
10
10
  def check_for_binding_pry(file)
11
- result = `grep -n "binding\\.pry" #{file}`.chomp
12
-
13
- unless result.empty?
14
- puts " pry -> FAIL, ".red
15
- puts result
16
- else
17
- print " pry -> OK, ".green
18
- end
19
-
20
- result.empty?
11
+ !plain_command("grep -n \"binding\\.pry\" #{file}", :bundler => false)
21
12
  end
22
13
 
23
14
  def check_for_binding_remote_pry(file)
24
- result = `grep -n "binding\\.remote_pry" #{file}`.chomp
25
-
26
- unless result.empty?
27
- puts " remote_pry -> FAIL".red
28
- puts result
29
- else
30
- print " remote_pry -> OK".green
31
- end
32
- puts ""
33
-
34
- result.empty?
15
+ !plain_command("grep -n \"binding\\.remote_pry\" #{file}", :bundler => false)
35
16
  end
36
17
  end
37
18
  end
@@ -4,7 +4,7 @@ module Checker
4
4
  extensions 'rb'
5
5
  private
6
6
  def check_one(file)
7
- command("ruby -c #{file}", :append => ">> /dev/null")
7
+ plain_command("ruby -c #{file}", :bundler => false)
8
8
  end
9
9
  end
10
10
  end
@@ -4,11 +4,11 @@ module Checker
4
4
  extensions 'scss', 'sass'
5
5
  private
6
6
  def check_one(file)
7
- command("sass #{file}", :use_bundler => true, :append => ">> /dev/null")
7
+ plain_command("sass #{file}")
8
8
  end
9
9
 
10
10
  def check_for_executable
11
- command("sass -v", :use_bundler => true, :show_output => false, :append => ">> /dev/null 2>&1")
11
+ silent_command("sass -v")
12
12
  end
13
13
 
14
14
  def dependency_message
@@ -0,0 +1,21 @@
1
+ module Checker
2
+ module Modules
3
+ class Slim < Base
4
+ extensions 'slim'
5
+ private
6
+ def check_one(file)
7
+ plain_command("slimrb --compile #{file} >> /dev/null")
8
+ end
9
+
10
+ def check_for_executable
11
+ silent_command("slimrb -v")
12
+ end
13
+
14
+ def dependency_message
15
+ str = "Executable not found\n"
16
+ str << "Install slim from rubygems: 'gem install slim'\n"
17
+ str
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ require 'yaml'
2
+
3
+ module Checker
4
+ module Modules
5
+ class Yaml < Base
6
+ extensions 'yaml', 'yml'
7
+ private
8
+ def check_one(file)
9
+ ret = begin
10
+ YAML.load_file(file)
11
+ true
12
+ rescue Exception => e
13
+ puts e
14
+ false
15
+ end
16
+ show_status(ret)
17
+ ret
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module Checker
2
+ VERSION = '0.0.6'
3
+ end
@@ -17,13 +17,6 @@ module Checker
17
17
  end
18
18
 
19
19
  describe Checker::CLI do
20
- before do
21
- @argv_copy = ARGV
22
- end
23
- after do
24
- ARGV = @argv_copy
25
- end
26
-
27
20
  context "running without arguments" do
28
21
  it "should run checks on modules from git config" do
29
22
  ARGV.stub(:size).and_return 0
@@ -35,7 +28,7 @@ describe Checker::CLI do
35
28
 
36
29
  context "running with argument" do
37
30
  it "should run check on modules from argument" do
38
- ARGV = ["pry"]
31
+ stub_const("ARGV", ["pry"])
39
32
  Checker::CLI.should_not_receive(:get_modules_to_check)
40
33
  Checker::CLI.should_receive(:exit).with(0).and_return true
41
34
  Checker::CLI.execute
@@ -0,0 +1,4 @@
1
+ binding.pry
2
+ def test
3
+ end
4
+ binding.remote_pry
@@ -0,0 +1,3 @@
1
+ def test
2
+ binding.pry
3
+ end
@@ -0,0 +1,3 @@
1
+ def test
2
+ binding.remote_pry
3
+ end
@@ -0,0 +1,2 @@
1
+ def test
2
+ end
@@ -0,0 +1,3 @@
1
+ def test
2
+ {some: 'random', hash: 'qwe'}
3
+ end
@@ -0,0 +1,2 @@
1
+ def test
2
+ {:some => 'random', :hash => 'qwe'}
@@ -0,0 +1,3 @@
1
+ def test
2
+ {:some => 'random', :hash => 'qwe'}
3
+ end
@@ -0,0 +1,2 @@
1
+ def test
2
+ {:some => 'random', :hash => 'qwe'}
@@ -0,0 +1,3 @@
1
+ def test
2
+ {some: 'random', hash: 'qwe'}
3
+ end
@@ -0,0 +1,18 @@
1
+ defaults: &defaults
2
+ mobile_ipad: "iPad"
3
+ mobile_agents:
4
+ - "AppleWebKit.+Mobile"
5
+ - "webOS"
6
+ - "SymbianOS"
7
+ - "AppleWebKit.+midori"
8
+ new_search_config:
9
+ options:
10
+ suffix: "/search"
11
+ params:
12
+ a: "a"
13
+ b: "b"
14
+
15
+ test:
16
+ <<: *defaults
17
+ discount: 0.12
18
+ host: test.test
@@ -0,0 +1,18 @@
1
+ defaults: &defaults
2
+ mobile_ipad: "iPad"
3
+ mobile_agents:
4
+ - "AppleWebKit.+Mobile"
5
+ - "webOS"
6
+ - "SymbianOS"
7
+ - "AppleWebKit.+midori"
8
+ new_search_config:
9
+ options:
10
+ suffix: "/search"
11
+ params:
12
+ a: "a"
13
+ b: "b"
14
+
15
+ test:
16
+ <<: *defaults
17
+ discount: 0.12
18
+ host: test.test
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe Checker::Modules::Coffeescript do
4
+ it 'should only check .coffee files' do
5
+ files = ['a.rb', 'b.js.erb', 'c.r', 'd.yml', 'e.yaml', 'f.coffee']
6
+ mod = Checker::Modules::Coffeescript.new(files)
7
+ mod.stub(:check_for_executable).and_return(true)
8
+ mod.should_receive(:check_one_file).with('f.coffee')
9
+ mod.should_not_receive(:check_one_file).with('e.yaml')
10
+ mod.should_not_receive(:check_one_file).with('d.yml')
11
+ mod.should_not_receive(:check_one_file).with('a.rb')
12
+ mod.should_not_receive(:check_one_file).with('b.js.erb')
13
+ mod.should_not_receive(:check_one_file).with('c.r')
14
+ mod.check
15
+ end
16
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe Checker::Modules::Haml do
4
+ it 'should only check .haml files' do
5
+ files = ['a.rb', 'b.js.erb', 'c.r', 'd.yml', 'e.yaml', 'f.coffee', 'g.haml']
6
+ mod = Checker::Modules::Haml.new(files)
7
+ mod.stub(:check_for_executable).and_return(true)
8
+ mod.stub(:check_one_file).and_return(true)
9
+ mod.should_receive(:check_one_file).with('g.haml')
10
+ mod.should_not_receive(:check_one_file).with('f.coffee')
11
+ mod.should_not_receive(:check_one_file).with('e.yaml')
12
+ mod.should_not_receive(:check_one_file).with('d.yml')
13
+ mod.should_not_receive(:check_one_file).with('a.rb')
14
+ mod.should_not_receive(:check_one_file).with('b.js.erb')
15
+ mod.should_not_receive(:check_one_file).with('c.r')
16
+ mod.check
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe Checker::Modules::Javascript do
4
+ it 'should only check .js files' do
5
+ files = ['a.rb', 'b.js.erb', 'c.r', 'd.yml', 'e.yaml', 'f.coffee', 'g.haml', 'h.js']
6
+ mod = Checker::Modules::Javascript.new(files)
7
+ mod.stub(:check_for_executable).and_return(true)
8
+ mod.should_receive(:check_one_file).with('h.js').and_return(true)
9
+ mod.should_not_receive(:check_one_file).with('g.haml')
10
+ mod.should_not_receive(:check_one_file).with('f.coffee')
11
+ mod.should_not_receive(:check_one_file).with('e.yaml')
12
+ mod.should_not_receive(:check_one_file).with('d.yml')
13
+ mod.should_not_receive(:check_one_file).with('a.rb')
14
+ mod.should_not_receive(:check_one_file).with('b.js.erb')
15
+ mod.should_not_receive(:check_one_file).with('c.r')
16
+ mod.check
17
+ end
18
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe Checker::Modules::Pry do
4
+ it 'should check all files' do
5
+ files = ['a.rb', 'b.js.erb', 'c.r', 'd.yaml', 'e.yml', 'f.coffee']
6
+ mod = Checker::Modules::Pry.new(files)
7
+ mod.stub(:check_one).and_return(true)
8
+ mod.should_receive(:check_one).exactly(6).times
9
+ mod.check
10
+ end
11
+
12
+ it "should not find the pry or remote_pry" do
13
+ files = [fixture("pry", "without_pry.rb")]
14
+ mod = Checker::Modules::Pry.new(files)
15
+ mod.check.should be_true
16
+ end
17
+
18
+ it "should find the pry or remote_pry" do
19
+ files = [fixture("pry", "with_pry.rb")]
20
+ mod = Checker::Modules::Pry.new(files)
21
+ mod.check.should be_false
22
+ end
23
+
24
+ it "should find the pry or remote_pry" do
25
+ files = [fixture("pry", "with_pry_remote.rb")]
26
+ mod = Checker::Modules::Pry.new(files)
27
+ mod.check.should be_false
28
+ end
29
+
30
+ it "should find the pry or remote_pry" do
31
+ files = [fixture("pry", "with_both.rb")]
32
+ mod = Checker::Modules::Pry.new(files)
33
+ mod.check.should be_false
34
+ end
35
+ end
@@ -4,8 +4,46 @@ describe Checker::Modules::Ruby do
4
4
  it 'should only check .rb files' do
5
5
  files = ['a.rb', 'b.js.erb', 'c.r']
6
6
  mod = Checker::Modules::Ruby.new(files)
7
- mod.stub(:check_one).and_return(true)
8
- mod.should_receive(:check_one).once
7
+ mod.stub(:check_one_file).and_return(true)
8
+ mod.should_receive(:check_one_file).with('a.rb')
9
+ mod.should_not_receive(:check_one_file).with('b.js.erb')
10
+ mod.should_not_receive(:check_one_file).with('c.r')
9
11
  mod.check
10
12
  end
11
- end
13
+
14
+ # 1.8
15
+ if RUBY_VERSION < "1.9"
16
+ it "should pass the syntax check" do
17
+ files = [fixture("ruby", "1.8/good.rb")]
18
+ mod = Checker::Modules::Ruby.new(files)
19
+ mod.check.should be_true
20
+ end
21
+
22
+ it "should not pass the syntax check" do
23
+ files = [fixture("ruby", "1.8/bad.rb")]
24
+ mod = Checker::Modules::Ruby.new(files)
25
+ mod.check.should be_false
26
+ end
27
+
28
+ it "should not pass the syntax check" do
29
+ files = [fixture("ruby", "1.8/bad2.rb")]
30
+ mod = Checker::Modules::Ruby.new(files)
31
+ mod.check.should be_false
32
+ end
33
+ end
34
+
35
+ if RUBY_VERSION >= "1.9"
36
+ it "should pass the syntax check" do
37
+ files = [fixture("ruby", "1.9/good.rb")]
38
+ mod = Checker::Modules::Ruby.new(files)
39
+ mod.check.should be_true
40
+ end
41
+
42
+ it "should not pass the syntax check" do
43
+ files = [fixture("ruby", "1.9/bad.rb")]
44
+ mod = Checker::Modules::Ruby.new(files)
45
+ mod.check.should be_false
46
+ end
47
+ end
48
+ # 1.9
49
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe Checker::Modules::Sass do
4
+ it 'should only check .sass and .scss files' do
5
+ files = ['a.rb', 'b.js.erb', 'c.r', 'd.yml', 'e.yaml', 'f.coffee', 'g.haml', 'h.js', 'i.scss', 'j.sass']
6
+ mod = Checker::Modules::Sass.new(files)
7
+ mod.stub(:check_for_executable).and_return(true)
8
+ mod.stub(:check_one_file).and_return(true)
9
+ mod.should_receive(:check_one_file).with('j.sass')
10
+ mod.should_receive(:check_one_file).with('i.scss')
11
+ mod.should_not_receive(:check_one_file).with('h.js')
12
+ mod.should_not_receive(:check_one_file).with('g.haml')
13
+ mod.should_not_receive(:check_one_file).with('f.coffee')
14
+ mod.should_not_receive(:check_one_file).with('e.yaml')
15
+ mod.should_not_receive(:check_one_file).with('d.yml')
16
+ mod.should_not_receive(:check_one_file).with('a.rb')
17
+ mod.should_not_receive(:check_one_file).with('b.js.erb')
18
+ mod.should_not_receive(:check_one_file).with('c.r')
19
+ mod.check
20
+ end
21
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe Checker::Modules::Slim do
4
+ it 'should only check .slim files' do
5
+ files = ['a.rb', 'b.js.erb', 'c.r', 'd.yml', 'e.yaml', 'f.coffee', 'g.slim']
6
+ mod = Checker::Modules::Slim.new(files)
7
+ mod.stub(:check_for_executable).and_return(true)
8
+ mod.stub(:check_one_file).and_return(true)
9
+ mod.should_receive(:check_one_file).with('g.slim')
10
+ mod.should_not_receive(:check_one_file).with('f.coffee')
11
+ mod.should_not_receive(:check_one_file).with('e.yaml')
12
+ mod.should_not_receive(:check_one_file).with('d.yml')
13
+ mod.should_not_receive(:check_one_file).with('a.rb')
14
+ mod.should_not_receive(:check_one_file).with('b.js.erb')
15
+ mod.should_not_receive(:check_one_file).with('c.r')
16
+ mod.check
17
+ end
18
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe Checker::Modules::Yaml do
4
+ it 'should only check .yaml and .yml files' do
5
+ files = ['a.rb', 'b.js.erb', 'c.r', 'd.yml', 'e.yaml']
6
+ mod = Checker::Modules::Yaml.new(files)
7
+ mod.stub(:check_one_file).and_return(true)
8
+ mod.should_receive(:check_one_file).with('d.yml')
9
+ mod.should_receive(:check_one_file).with('e.yaml')
10
+ mod.should_not_receive(:check_one_file).with('a.rb')
11
+ mod.should_not_receive(:check_one_file).with('b.js.erb')
12
+ mod.should_not_receive(:check_one_file).with('c.r')
13
+ mod.check
14
+ end
15
+
16
+ it "should properly fetch yaml files" do
17
+ files = [fixture("yaml", "good.yaml")]
18
+ mod = Checker::Modules::Yaml.new(files)
19
+ mod.check.should be_true
20
+ end
21
+
22
+ it "should not pass the syntax check" do
23
+ files = [fixture("yaml", "bad.yaml")]
24
+ mod = Checker::Modules::Yaml.new(files)
25
+ mod.check.should be_false
26
+ end
27
+ end
@@ -1,3 +1,25 @@
1
+ require 'digest/md5'
2
+
1
3
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
4
 
3
- require 'checker/cli'
5
+ FIXTURES_PATH = File.join(File.dirname(__FILE__), "checker", "fixtures")
6
+
7
+ def fixture(dir, filename)
8
+ "#{FIXTURES_PATH}/#{dir}/#{filename}"
9
+ end
10
+
11
+ def digest filename
12
+ Digest::MD5.hexdigest(filename)
13
+ end
14
+
15
+ require 'checker/cli'
16
+
17
+ module Checker
18
+ module Modules
19
+ class Base
20
+ def checkout_file file_name, target
21
+ `cp #{file_name} #{checkout_file_name(target)} > /dev/null 2>&1`
22
+ end
23
+ end
24
+ end
25
+ end
metadata CHANGED
@@ -1,30 +1,38 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: checker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jacek Jakubik
9
+ - Tomasz Pewiński
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2012-07-11 00:00:00.000000000 Z
13
+ date: 2012-08-28 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: colorize
16
- requirement: &70291943302500 !ruby/object:Gem::Requirement
17
+ requirement: !ruby/object:Gem::Requirement
17
18
  none: false
18
19
  requirements:
19
- - - =
20
+ - - '='
20
21
  - !ruby/object:Gem::Version
21
22
  version: 0.5.8
22
23
  type: :runtime
23
24
  prerelease: false
24
- version_requirements: *70291943302500
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - '='
29
+ - !ruby/object:Gem::Version
30
+ version: 0.5.8
25
31
  description: A collection of modules which every is designed to check syntax for specific
26
32
  files.
27
- email: jacek.jakubik@netguru.pl
33
+ email:
34
+ - jacek.jakubik@netguru.pl
35
+ - tomasz.pewinski@netguru.pl
28
36
  executables:
29
37
  - checker
30
38
  - prepare-commit-msg
@@ -32,7 +40,10 @@ extensions: []
32
40
  extra_rdoc_files: []
33
41
  files:
34
42
  - .gitignore
43
+ - .travis.yml
35
44
  - CHANGELOG
45
+ - Gemfile
46
+ - Gemfile.lock
36
47
  - README.md
37
48
  - Rakefile
38
49
  - bin/checker
@@ -48,8 +59,29 @@ files:
48
59
  - lib/checker/modules/pry.rb
49
60
  - lib/checker/modules/ruby.rb
50
61
  - lib/checker/modules/sass.rb
62
+ - lib/checker/modules/slim.rb
63
+ - lib/checker/modules/yaml.rb
64
+ - lib/checker/version.rb
51
65
  - spec/checker/cli_spec.rb
66
+ - spec/checker/fixtures/pry/with_both.rb
67
+ - spec/checker/fixtures/pry/with_pry.rb
68
+ - spec/checker/fixtures/pry/with_pry_remote.rb
69
+ - spec/checker/fixtures/pry/without_pry.rb
70
+ - spec/checker/fixtures/ruby/1.8/bad.rb
71
+ - spec/checker/fixtures/ruby/1.8/bad2.rb
72
+ - spec/checker/fixtures/ruby/1.8/good.rb
73
+ - spec/checker/fixtures/ruby/1.9/bad.rb
74
+ - spec/checker/fixtures/ruby/1.9/good.rb
75
+ - spec/checker/fixtures/yaml/bad.yaml
76
+ - spec/checker/fixtures/yaml/good.yaml
77
+ - spec/checker/modules/coffeescript_spec.rb
78
+ - spec/checker/modules/haml_spec.rb
79
+ - spec/checker/modules/javascript_spec.rb
80
+ - spec/checker/modules/pry_spec.rb
52
81
  - spec/checker/modules/ruby_spec.rb
82
+ - spec/checker/modules/sass_spec.rb
83
+ - spec/checker/modules/slim_spec.rb
84
+ - spec/checker/modules/yaml_spec.rb
53
85
  - spec/spec_helper.rb
54
86
  homepage: http://github.com/netguru/checker
55
87
  licenses: []
@@ -71,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
103
  version: '0'
72
104
  requirements: []
73
105
  rubyforge_project:
74
- rubygems_version: 1.8.10
106
+ rubygems_version: 1.8.24
75
107
  signing_key:
76
108
  specification_version: 3
77
109
  summary: Syntax checker for various files