judge 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -5,6 +5,10 @@ rvm:
5
5
  before_script:
6
6
  - "export DISPLAY=:99.0"
7
7
  - "sh -e /etc/init.d/xvfb start"
8
+ - "git clone git://github.com/n1k0/casperjs.git"
9
+ - "cd casperjs"
10
+ - "git checkout tags/0.6.5"
11
+ - "sudo ln -sf `pwd`/bin/casperjs /usr/local/bin/casperjs"
8
12
 
9
13
  script: "bundle exec rake"
10
14
 
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ require 'rspec/core/rake_task'
5
5
  RSpec::Core::RakeTask.new("spec")
6
6
 
7
7
  load "jasmine/tasks/jasmine.rake"
8
- load "lib/tasks/js_tests.rake"
8
+ load "lib/tasks/js.rake"
9
9
 
10
10
  desc "Run all tests"
11
- task :default => ["spec", "jasmine:phantom"]
11
+ task :default => ["spec", "jasmine:headless"]
@@ -1,4 +1,4 @@
1
- // Judge 1.3.0
1
+ // Judge 1.4.0
2
2
  // (c) 2011–2012 Joe Corcoran
3
3
  // http://raw.github.com/joecorcoran/judge/master/LICENSE.txt
4
4
  // This is the JavaScript part of Judge, a client-side validation gem for Rails 3.
@@ -13,7 +13,7 @@
13
13
  // The judge namespace.
14
14
  var judge = {};
15
15
 
16
- judge.VERSION = '1.3.0';
16
+ judge.VERSION = '1.4.0';
17
17
 
18
18
  // A judge.Watcher is a DOM element wrapper that judge uses to store validation info and instance methods.
19
19
  judge.Watcher = function (element) {
@@ -245,9 +245,9 @@
245
245
 
246
246
  // Shortcut for `judge.validate(judge.store.getDOM(key));`.
247
247
  // Returns null if no stored elements are found for the given key.
248
- validate: function(key) {
248
+ validate: function(key, callback) {
249
249
  var elements = judge.store.getDOM(key);
250
- return (key && !_(elements).isNull()) ? judge.validate(elements) : null;
250
+ return (key && !_(elements).isNull()) ? judge.validate(elements, callback) : null;
251
251
  },
252
252
 
253
253
  // Wipes the entire store object, or wipes all watchers stored against
data/lib/judge/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Judge
2
- VERSION = "1.3.0"
2
+ VERSION = "1.4.0"
3
3
  end
@@ -1,25 +1,29 @@
1
1
  namespace :jasmine do
2
- task :require_phantom_js do
2
+ task :require_phantom do
3
3
  sh "which phantomjs" do |ok, res|
4
4
  fail 'Cannot find phantomjs on $PATH' unless ok
5
5
  end
6
6
  end
7
7
 
8
+ task :require_casper do
9
+ sh "which casperjs" do |ok, res|
10
+ fail 'Cannot find casperjs on $PATH' unless ok
11
+ end
12
+ end
13
+
8
14
  desc "Run continuous integration tests headlessly with phantom.js"
9
- task :phantom => ['jasmine:require', 'jasmine:require_phantom_js'] do
15
+ task :headless => ['jasmine:require', 'jasmine:require_phantom', 'jasmine:require_casper'] do
10
16
  support_dir = File.expand_path('../../spec/javascripts/support', File.dirname(__FILE__))
11
17
  config_overrides = File.join(support_dir, 'jasmine_config.rb')
12
18
  require config_overrides if File.exists?(config_overrides)
13
- phantom_js_runner = File.join(support_dir, 'phantomRunner.js')
14
-
19
+
20
+ test_runner = File.join(support_dir, 'runner.js')
15
21
  config = Jasmine::Config.new
16
-
17
- # start the Jasmine server and wait up to 10 seconds for it to be running:
18
22
  config.start_jasmine_server
19
23
 
20
24
  jasmine_url = "#{config.jasmine_host}:#{config.jasmine_server_port}"
21
25
  puts "Running tests against #{jasmine_url}"
22
- sh "phantomjs #{phantom_js_runner} #{jasmine_url}" do |ok, res|
26
+ sh "casperjs #{test_runner} #{jasmine_url}" do |ok, res|
23
27
  fail "jasmine suite failed" unless ok
24
28
  end
25
29
  end
@@ -448,6 +448,13 @@ describe('judge', function() {
448
448
  expect(_(results).first().element).toEqual(element);
449
449
  });
450
450
 
451
+ it('calls callback correct number of times', function() {
452
+ judge.store.save('mykey', document.getElementsByTagName('textarea'));
453
+ var callback = jasmine.createSpy();
454
+ judge.store.validate('mykey', callback);
455
+ expect(callback.callCount).toBe(4);
456
+ });
457
+
451
458
  it('returns null if no elements found', function() {
452
459
  var results = judge.store.validate('mykey');
453
460
  expect(results).toBe(null);
@@ -0,0 +1,51 @@
1
+ var casper = require('casper').create(),
2
+ path = casper.cli.args[0],
3
+ colorizer = require('colorizer').create(),
4
+ data;
5
+
6
+ casper
7
+ .start(path)
8
+ .then(function() {
9
+ this.waitForSelector('.finished-at', function() {
10
+ data = this.evaluate(readResults);
11
+ });
12
+ })
13
+ .run(function() {
14
+ this.echo(fmtTitle(data.desc, data.status));
15
+ if (data.messages.length > 0) {
16
+ this.echo(data.messages.join('\n\n') + '\n', colorType(data.status));
17
+ }
18
+ this.exit(data.status);
19
+ });
20
+
21
+ var readResults = function() {
22
+ var desc = document.querySelector('.runner .description').innerHTML,
23
+ msgs = [],
24
+ status = 0;
25
+ if (document.querySelector('.runner.failed')) {
26
+ var f = document.querySelectorAll('.spec.failed');
27
+ for (var i = 0, l = f.length; i < l; i += 1) {
28
+ var msg = ' ' + (i + 1) + '. '
29
+ + f[i].querySelector('.description').title
30
+ + ' (' + f[i].querySelector('.messages .resultMessage').innerHTML + ')';
31
+ msgs.push(msg);
32
+ };
33
+ status = 1;
34
+ };
35
+ return { desc: desc, messages: msgs, status: status };
36
+ };
37
+
38
+ var fmtTitle = function(string, status) {
39
+ var fail = (status === 1);
40
+ string = colorizer.format(string, {
41
+ fg: (fail ? 'red' : 'green'),
42
+ bold: true,
43
+ underscore: !!fail
44
+ });
45
+ string = '\n' + string + '\n';
46
+ return string;
47
+ };
48
+
49
+ var colorType = function(status) {
50
+ return (status === 1) ? 'WARNING' : 'INFO';
51
+ };
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: judge
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-04-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jasmine
16
- requirement: &2151893720 !ruby/object:Gem::Requirement
16
+ requirement: &2151873000 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.1.2
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2151893720
24
+ version_requirements: *2151873000
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rails
27
- requirement: &2151891300 !ruby/object:Gem::Requirement
27
+ requirement: &2151872120 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '3.2'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2151891300
35
+ version_requirements: *2151872120
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &2151890360 !ruby/object:Gem::Requirement
38
+ requirement: &2151871360 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '2.8'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2151890360
46
+ version_requirements: *2151871360
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: sqlite3-ruby
49
- requirement: &2151888920 !ruby/object:Gem::Requirement
49
+ requirement: &2151870580 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.3.3
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2151888920
57
+ version_requirements: *2151870580
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: factory_girl
60
- requirement: &2151886400 !ruby/object:Gem::Requirement
60
+ requirement: &2151869300 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '2.6'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *2151886400
68
+ version_requirements: *2151869300
69
69
  description: Validate Rails 3 forms on the client side, cleanly
70
70
  email: joe@tribesports.com
71
71
  executables: []
@@ -90,7 +90,7 @@ files:
90
90
  - lib/judge/validator.rb
91
91
  - lib/judge/validator_collection.rb
92
92
  - lib/judge/version.rb
93
- - lib/tasks/js_tests.rake
93
+ - lib/tasks/js.rake
94
94
  - spec/factories.rb
95
95
  - spec/form_builder_spec.rb
96
96
  - spec/html_spec.rb
@@ -104,7 +104,7 @@ files:
104
104
  - spec/javascripts/support/jasmine.yml
105
105
  - spec/javascripts/support/jasmine_config.rb
106
106
  - spec/javascripts/support/jasmine_runner.rb
107
- - spec/javascripts/support/phantomRunner.js
107
+ - spec/javascripts/support/runner.js
108
108
  - spec/message_collection_spec.rb
109
109
  - spec/setup.rb
110
110
  - spec/spec_helper.rb
@@ -124,7 +124,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
124
124
  version: '0'
125
125
  segments:
126
126
  - 0
127
- hash: -115448070476336005
127
+ hash: -196777786245842786
128
128
  required_rubygems_version: !ruby/object:Gem::Requirement
129
129
  none: false
130
130
  requirements:
@@ -133,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
133
  version: '0'
134
134
  segments:
135
135
  - 0
136
- hash: -115448070476336005
136
+ hash: -196777786245842786
137
137
  requirements: []
138
138
  rubyforge_project:
139
139
  rubygems_version: 1.8.15
@@ -154,7 +154,7 @@ test_files:
154
154
  - spec/javascripts/support/jasmine.yml
155
155
  - spec/javascripts/support/jasmine_config.rb
156
156
  - spec/javascripts/support/jasmine_runner.rb
157
- - spec/javascripts/support/phantomRunner.js
157
+ - spec/javascripts/support/runner.js
158
158
  - spec/message_collection_spec.rb
159
159
  - spec/setup.rb
160
160
  - spec/spec_helper.rb
@@ -1,28 +0,0 @@
1
- var page = new WebPage();
2
- page.open(phantom.args[0], function(status) {
3
- if (status !== 'success') {
4
- console.log('Cannot open Jasmine server page');
5
- phantom.exit();
6
- } else {
7
- window.setTimeout(function () {
8
- var result = page.evaluate(function() {
9
- var desc = document.querySelector('.runner .description').innerHTML;
10
- if (document.querySelector('.runner.failed')) {
11
- var failed = document.querySelectorAll('.spec.failed'),
12
- failMsgs = [],
13
- output = '';
14
- for (var i = 0, l = failed.length; i < l; i += 1) {
15
- var msg = ' - ' + failed[i].querySelector('.description').title + ' (' + failed[i].querySelector('.messages .resultMessage').innerHTML + ')';
16
- failMsgs.push(msg);
17
- };
18
- output = '\n' + failMsgs.length + ' specs failed:\n\n' + failMsgs.join('\n') + '\n\n' + desc;
19
- return { msg:output, code:1 };
20
- } else {
21
- return { msg:desc, code:0 };
22
- };
23
- });
24
- console.log(result.msg);
25
- phantom.exit(result.code);
26
- }, 400);
27
- };
28
- });