jslint_on_rails 1.0.0 → 1.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/Gemfile +8 -0
- data/README.markdown +2 -0
- data/Rakefile +8 -0
- data/lib/jslint.rb +3 -3
- data/{config → lib/jslint/config}/jslint.yml +2 -1
- data/lib/jslint/lint.rb +19 -8
- data/lib/jslint/rails.rb +3 -1
- data/lib/jslint/tasks.rb +2 -1
- data/lib/jslint/utils.rb +18 -9
- data/{vendor → lib/jslint/vendor}/jslint.js +412 -240
- data/{vendor → lib/jslint/vendor}/rhino.jar +0 -0
- data/{vendor → lib/jslint/vendor}/test.jar +0 -0
- data/spec/lint_spec.rb +142 -0
- data/spec/spec_helper.rb +8 -0
- data/spec/utils_spec.rb +148 -0
- metadata +21 -9
File without changes
|
File without changes
|
data/spec/lint_spec.rb
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe JSLint::Lint do
|
4
|
+
|
5
|
+
before :all do
|
6
|
+
File.open(JSLint::DEFAULT_CONFIG_FILE, "w") { |f| f.write "color: red\nsize: 5\nshape: circle\n" }
|
7
|
+
File.open("custom_config.yml", "w") { |f| f.write "color: blue\nsize: 7\nborder: 2\n" }
|
8
|
+
File.open("other_config.yml", "w") { |f| f.write "color: green\nborder: 0\nshape: square" }
|
9
|
+
JSLint.config_path = "custom_config.yml"
|
10
|
+
end
|
11
|
+
|
12
|
+
def setup_java(lint)
|
13
|
+
lint.should_receive(:call_java_with_output).once.and_return("OK")
|
14
|
+
end
|
15
|
+
|
16
|
+
def file_list(lint)
|
17
|
+
lint.instance_variable_get("@file_list")
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should merge default config with custom config from JSLint.config_path" do
|
21
|
+
lint = JSLint::Lint.new
|
22
|
+
config = lint.instance_variable_get("@config")
|
23
|
+
config.should == { 'color' => 'blue', 'size' => 7, 'border' => 2, 'shape' => 'circle' }
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should merge default config with custom config given in argument, if available" do
|
27
|
+
lint = JSLint::Lint.new :config_path => 'other_config.yml'
|
28
|
+
config = lint.instance_variable_get("@config")
|
29
|
+
config.should == { 'color' => 'green', 'border' => 0, 'shape' => 'square', 'size' => 5 }
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should not pass paths and exclude_paths options to real JSLint" do
|
33
|
+
File.open("test.yml", "w") do |f|
|
34
|
+
f.write(YAML.dump({ 'paths' => ['a', 'b'], 'exclude_paths' => ['c'], 'debug' => 'true' }))
|
35
|
+
end
|
36
|
+
lint = JSLint::Lint.new :config_path => 'test.yml'
|
37
|
+
config = lint.instance_variable_get("@config")
|
38
|
+
config['debug'].should == 'true'
|
39
|
+
config['paths'].should be_nil
|
40
|
+
config['exclude_paths'].should be_nil
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should fail if Java isn't available" do
|
44
|
+
lint = JSLint::Lint.new
|
45
|
+
lint.should_receive(:call_java_with_output).once.and_return("java: command not found")
|
46
|
+
lambda { lint.run }.should raise_error(JSLint::NoJavaException)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should fail if JSLint check fails" do
|
50
|
+
lint = JSLint::Lint.new
|
51
|
+
setup_java(lint)
|
52
|
+
lint.should_receive(:call_java_with_status).once.and_return(false)
|
53
|
+
lambda { lint.run }.should raise_error(JSLint::LintCheckFailure)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should not fail if JSLint check passes" do
|
57
|
+
lint = JSLint::Lint.new
|
58
|
+
setup_java(lint)
|
59
|
+
lint.should_receive(:call_java_with_status).once.and_return(true)
|
60
|
+
lambda { lint.run }.should_not raise_error
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should only do Java check once" do
|
64
|
+
lint = JSLint::Lint.new
|
65
|
+
setup_java(lint)
|
66
|
+
lint.should_receive(:call_java_with_status).twice.and_return(true)
|
67
|
+
lambda do
|
68
|
+
lint.run
|
69
|
+
lint.run
|
70
|
+
end.should_not raise_error(JSLint::NoJavaException)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should pass comma-separated option string to JSLint" do
|
74
|
+
lint = JSLint::Lint.new
|
75
|
+
lint.instance_variable_set("@config", { 'debug' => true, 'semicolons' => false, 'linelength' => 120 })
|
76
|
+
setup_java(lint)
|
77
|
+
lint.
|
78
|
+
should_receive(:call_java_with_status).
|
79
|
+
once.
|
80
|
+
with(an_instance_of(String), an_instance_of(String), /semicolons=false,linelength=120,debug=true/).
|
81
|
+
and_return(true)
|
82
|
+
lint.run
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should pass space-separated list of files to JSLint" do
|
86
|
+
lint = JSLint::Lint.new
|
87
|
+
lint.instance_variable_set("@file_list", ['app.js', 'test.js', 'jquery.js'])
|
88
|
+
setup_java(lint)
|
89
|
+
lint.
|
90
|
+
should_receive(:call_java_with_status).
|
91
|
+
once.
|
92
|
+
with(an_instance_of(String), an_instance_of(String), /app\.js test\.js jquery\.js$/).
|
93
|
+
and_return(true)
|
94
|
+
lint.run
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "file lists" do
|
98
|
+
before :each do
|
99
|
+
JSLint::Utils.stub!(:exclude_files).and_return { |inc, exc| inc - exc }
|
100
|
+
JSLint::Utils.stub!(:unique_files).and_return { |files| files.uniq }
|
101
|
+
end
|
102
|
+
|
103
|
+
before :all do
|
104
|
+
@files = ['test/app.js', 'test/lib.js', 'test/utils.js', 'test/vendor/jquery.js', 'test/vendor/proto.js']
|
105
|
+
@files.each { |fn| File.open(fn, "w") { |f| f.write("alert()") }}
|
106
|
+
@files = @files.map { |fn| File.expand_path(fn) }
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should calculate a list of files to test" do
|
110
|
+
lint = JSLint::Lint.new :paths => ['test/**/*.js']
|
111
|
+
file_list(lint).should == @files
|
112
|
+
|
113
|
+
lint = JSLint::Lint.new :paths => ['test/a*.js', 'test/**/*r*.js']
|
114
|
+
file_list(lint).should == [@files[0], @files[3], @files[4]]
|
115
|
+
|
116
|
+
lint = JSLint::Lint.new :paths => ['test/a*.js', 'test/**/*r*.js'], :exclude_paths => ['**/*q*.js']
|
117
|
+
file_list(lint).should == [@files[0], @files[4]]
|
118
|
+
|
119
|
+
lint = JSLint::Lint.new :paths => ['test/**/*.js'], :exclude_paths => ['**/*.js']
|
120
|
+
file_list(lint).should == []
|
121
|
+
|
122
|
+
lint = JSLint::Lint.new :paths => ['test/**/*.js', 'test/**/a*.js', 'test/**/p*.js']
|
123
|
+
file_list(lint).should == @files
|
124
|
+
|
125
|
+
File.open("new.yml", "w") { |f| f.write(YAML.dump({ 'paths' => ['test/vendor/*.js'] })) }
|
126
|
+
|
127
|
+
lint = JSLint::Lint.new :config_path => 'new.yml', :exclude_paths => ['**/proto.js']
|
128
|
+
file_list(lint).should == [@files[3]]
|
129
|
+
|
130
|
+
lint = JSLint::Lint.new :config_path => 'new.yml', :paths => ['test/l*.js']
|
131
|
+
file_list(lint).should == [@files[1]]
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should accept :paths and :exclude_paths as string instead of one-element array" do
|
135
|
+
lambda do
|
136
|
+
lint = JSLint::Lint.new :paths => 'test/*.js', :exclude_paths => 'test/lib.js'
|
137
|
+
file_list(lint).should == [@files[0], @files[2]]
|
138
|
+
end.should_not raise_error
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/spec/utils_spec.rb
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe JSLint::Utils do
|
4
|
+
|
5
|
+
JSU = JSLint::Utils
|
6
|
+
|
7
|
+
before :all do
|
8
|
+
File.open(JSLint::DEFAULT_CONFIG_FILE, "w") { |f| f.puts "default config file" }
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should have a config_path setting" do
|
12
|
+
JSLint.config_path = 'some/path'
|
13
|
+
JSLint.config_path.should == 'some/path'
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "paths_from_command_line" do
|
17
|
+
it "should extract an array of paths from command line argument" do
|
18
|
+
ENV['test_arg'] = 'one,two,three'
|
19
|
+
JSU.paths_from_command_line('test_arg').should == ['one', 'two', 'three']
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should also work if the argument name is given in uppercase" do
|
23
|
+
ENV['TEST_ARG'] = 'ruby,python,js'
|
24
|
+
JSU.paths_from_command_line('test_arg').should == ['ruby', 'python', 'js']
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should return nil if the argument isn't set" do
|
28
|
+
JSU.paths_from_command_line('crash').should be_nil
|
29
|
+
end
|
30
|
+
|
31
|
+
after :each do
|
32
|
+
ENV['test_arg'] = nil
|
33
|
+
ENV['TEST_ARG'] = nil
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "load_config_file" do
|
38
|
+
|
39
|
+
before :all do
|
40
|
+
File.open("sample.yml", "w") { |f| f.puts("framework: rails") }
|
41
|
+
Dir.mkdir("tmp")
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should load a YAML file if it can be read" do
|
45
|
+
JSU.load_config_file("sample.yml").should == { 'framework' => 'rails' }
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should return an empty hash if file name is nil" do
|
49
|
+
JSU.load_config_file(nil).should == {}
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should return an empty hash if file doesn't exist" do
|
53
|
+
JSU.load_config_file("crack.exe").should == {}
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should return an empty hash if file is not a file" do
|
57
|
+
JSU.load_config_file("tmp").should == {}
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should return an empty hash if file is not readable" do
|
61
|
+
File.should_receive(:readable?).once.with("sample.yml").and_return(false)
|
62
|
+
JSU.load_config_file("sample.yml").should == {}
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "unique and exclude" do
|
67
|
+
def set_identical(file1, file2, value)
|
68
|
+
File.should_receive(:identical?).with(file1, file2).once.and_return(value)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should remove duplicate files from a list" do
|
72
|
+
set_identical('config.yml', 'lib/../config.yml', true)
|
73
|
+
set_identical('config.yml', 'Rakefile', false)
|
74
|
+
set_identical('config.yml', 'Config.yml', true)
|
75
|
+
unique = JSU.unique_files(['config.yml', 'lib/../config.yml', 'Rakefile', 'Config.yml'])
|
76
|
+
unique.should == ['config.yml', 'Rakefile']
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should subtract files on the second list from the first list" do
|
80
|
+
set_identical('RaKeFiLe', 'config.yml', false)
|
81
|
+
set_identical('wtf', 'config.yml', false)
|
82
|
+
set_identical('Config.yml', 'config.yml', true)
|
83
|
+
set_identical('RaKeFiLe', 'Rakefile', true)
|
84
|
+
set_identical('RaKeFiLe', 'Gemfile', false)
|
85
|
+
set_identical('wtf', 'Gemfile', false)
|
86
|
+
set_identical('Config.yml', 'Gemfile', false)
|
87
|
+
included = JSU.exclude_files(['config.yml', 'Rakefile', 'Gemfile'], ['RaKeFiLe', 'wtf', 'Config.yml'])
|
88
|
+
included.should == ['Gemfile']
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "copy_config_file" do
|
93
|
+
it "throw an error if config path isn't set" do
|
94
|
+
JSLint.config_path = nil
|
95
|
+
lambda { JSLint::Utils.copy_config_file }.should raise_error(ArgumentError)
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should copy default config to config_path" do
|
99
|
+
JSLint.config_path = "newfile.yml"
|
100
|
+
File.should_receive(:copy).with(JSLint::DEFAULT_CONFIG_FILE, "newfile.yml")
|
101
|
+
JSLint::Utils.copy_config_file
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should not overwrite the file if it exists" do
|
105
|
+
JSLint.config_path = "newfile2.yml"
|
106
|
+
File.open("newfile2.yml", "w") { |f| f.write("qwe") }
|
107
|
+
File.should_not_receive(:copy)
|
108
|
+
JSLint::Utils.copy_config_file
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe "remove_config_file" do
|
113
|
+
it "throw an error if config path isn't set" do
|
114
|
+
JSLint.config_path = nil
|
115
|
+
lambda { JSLint::Utils.remove_config_file }.should raise_error(ArgumentError)
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should remove the file if it's identical to default one" do
|
119
|
+
JSLint.config_path = "newfile3.yml"
|
120
|
+
File.open("newfile3.yml", "w") { |f| f.puts("default config file") }
|
121
|
+
File.exists?("newfile3.yml").should be_true
|
122
|
+
JSLint::Utils.remove_config_file
|
123
|
+
File.exists?("newfile3.yml").should be_false
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should not remove the file if it's not identical to default one" do
|
127
|
+
JSLint.config_path = "newfile4.yml"
|
128
|
+
File.open("newfile4.yml", "w") { |f| f.puts("something's changed") }
|
129
|
+
File.exists?("newfile4.yml").should be_true
|
130
|
+
JSLint::Utils.remove_config_file
|
131
|
+
File.exists?("newfile4.yml").should be_true
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should not remove the file if it doesn't exist" do
|
135
|
+
JSLint.config_path = "this_doesnt_exist.yml"
|
136
|
+
lambda { JSLint::Utils.remove_config_file }.should_not raise_error
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should not remove the file if it's not a file" do
|
140
|
+
Dir.mkdir("public")
|
141
|
+
JSLint.config_path = "public"
|
142
|
+
lambda { JSLint::Utils.remove_config_file }.should_not raise_error
|
143
|
+
File.exist?("public").should be_true
|
144
|
+
File.directory?("public").should be_true
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jslint_on_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
version: 1.0.2
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Jakub Suder
|
@@ -9,7 +14,7 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date:
|
17
|
+
date: 2010-04-10 00:00:00 +02:00
|
13
18
|
default_executable:
|
14
19
|
dependencies: []
|
15
20
|
|
@@ -24,16 +29,21 @@ extra_rdoc_files: []
|
|
24
29
|
files:
|
25
30
|
- MIT-LICENSE
|
26
31
|
- README.markdown
|
27
|
-
-
|
32
|
+
- Gemfile
|
33
|
+
- Rakefile
|
34
|
+
- lib/jslint/config/jslint.yml
|
28
35
|
- lib/jslint/errors.rb
|
29
36
|
- lib/jslint/lint.rb
|
30
37
|
- lib/jslint/rails.rb
|
31
38
|
- lib/jslint/tasks.rb
|
32
39
|
- lib/jslint/utils.rb
|
40
|
+
- lib/jslint/vendor/jslint.js
|
41
|
+
- lib/jslint/vendor/rhino.jar
|
42
|
+
- lib/jslint/vendor/test.jar
|
33
43
|
- lib/jslint.rb
|
34
|
-
-
|
35
|
-
-
|
36
|
-
-
|
44
|
+
- spec/lint_spec.rb
|
45
|
+
- spec/spec_helper.rb
|
46
|
+
- spec/utils_spec.rb
|
37
47
|
has_rdoc: true
|
38
48
|
homepage: http://github.com/psionides/jslint_on_rails
|
39
49
|
licenses: []
|
@@ -47,18 +57,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
47
57
|
requirements:
|
48
58
|
- - ">="
|
49
59
|
- !ruby/object:Gem::Version
|
60
|
+
segments:
|
61
|
+
- 0
|
50
62
|
version: "0"
|
51
|
-
version:
|
52
63
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
64
|
requirements:
|
54
65
|
- - ">="
|
55
66
|
- !ruby/object:Gem::Version
|
67
|
+
segments:
|
68
|
+
- 0
|
56
69
|
version: "0"
|
57
|
-
version:
|
58
70
|
requirements:
|
59
71
|
- Java JRE (5.0 or later)
|
60
72
|
rubyforge_project:
|
61
|
-
rubygems_version: 1.3.
|
73
|
+
rubygems_version: 1.3.6
|
62
74
|
signing_key:
|
63
75
|
specification_version: 3
|
64
76
|
summary: JSLint JavaScript checker wrapped in a Ruby gem for easier use
|