chai-jquery-rails 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitmodules CHANGED
@@ -1,3 +1,3 @@
1
1
  [submodule "chai-jquery"]
2
2
  path = chai-jquery
3
- url = https://github.com/chaijs/chai-jquery
3
+ url = https://github.com/chaijs/chai-jquery.git
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  [chai-jquery](https://github.com/chaijs/chai-jquery) is a plugin for
4
4
  [chai](http://chaijs.com/) that gives you jquery expectation helpers.
5
5
 
6
- This is a simple gem that adds chai-jquery to rails asset pipline.
6
+ This is a simple gem that adds chai-jquery to the rails asset pipline.
7
7
 
8
8
 
9
9
  ## Installation
@@ -1,7 +1,7 @@
1
1
  module Chai
2
2
  module Jquery
3
3
  module Rails
4
- VERSION = "0.0.2"
4
+ VERSION = "0.0.3"
5
5
  end
6
6
  end
7
7
  end
@@ -9,9 +9,8 @@
9
9
  return chaiJquery;
10
10
  });
11
11
  } else {
12
- // Other environment (usually <script> tag): pass into global chai
13
- var global = (false || eval)("this");
14
- global.chai.use(chaiJquery);
12
+ // Other environment (usually <script> tag): plug in to global chai instance directly.
13
+ chai.use(chaiJquery);
15
14
  }
16
15
  }(function (chai, utils) {
17
16
  var inspect = utils.inspect,
@@ -28,30 +27,35 @@
28
27
  return el.html();
29
28
  };
30
29
 
31
- chai.Assertion.addMethod('attr', function (name, val) {
32
- var actual = flag(this, 'object').attr(name);
30
+ var props = {attr: 'attribute', css: 'CSS property'};
31
+ for (var prop in props) {
32
+ (function (prop, description) {
33
+ chai.Assertion.addMethod(prop, function (name, val) {
34
+ var actual = flag(this, 'object')[prop](name);
33
35
 
34
- if (!flag(this, 'negate') || undefined === val) {
35
- this.assert(
36
- undefined !== actual
37
- , 'expected #{this} to have a #{exp} attribute'
38
- , 'expected #{this} not to have a #{exp} attribute'
39
- , name
40
- );
41
- }
36
+ if (!flag(this, 'negate') || undefined === val) {
37
+ this.assert(
38
+ undefined !== actual
39
+ , 'expected #{this} to have a #{exp} ' + description
40
+ , 'expected #{this} not to have a #{exp} ' + description
41
+ , name
42
+ );
43
+ }
42
44
 
43
- if (undefined !== val) {
44
- this.assert(
45
- val === actual
46
- , 'expected #{this} to have a ' + inspect(name) + ' attribute with the value #{exp}, but the value was #{act}'
47
- , 'expected #{this} not to have a ' + inspect(name) + ' attribute with the value #{act}'
48
- , val
49
- , actual
50
- );
51
- }
45
+ if (undefined !== val) {
46
+ this.assert(
47
+ val === actual
48
+ , 'expected #{this} to have a ' + inspect(name) + ' ' + description + ' with the value #{exp}, but the value was #{act}'
49
+ , 'expected #{this} not to have a ' + inspect(name) + ' ' + description + ' with the value #{act}'
50
+ , val
51
+ , actual
52
+ );
53
+ }
52
54
 
53
- flag(this, 'object', actual);
54
- });
55
+ flag(this, 'object', actual);
56
+ });
57
+ })(prop, props[prop]);
58
+ }
55
59
 
56
60
  chai.Assertion.addMethod('data', function (name, val) {
57
61
  // Work around a chai bug (https://github.com/logicalparadox/chai/issues/16)
@@ -62,7 +66,7 @@
62
66
  var assertion = new chai.Assertion(flag(this, 'object').data());
63
67
  if (flag(this, 'negate'))
64
68
  assertion = assertion.not;
65
- assertion.property(name, val);
69
+ return assertion.property(name, val);
66
70
  });
67
71
 
68
72
  chai.Assertion.addMethod('class', function (className) {
@@ -133,6 +137,20 @@
133
137
  };
134
138
  });
135
139
 
140
+ chai.Assertion.overwriteProperty('empty', function (_super) {
141
+ return function () {
142
+ var obj = flag(this, 'object');
143
+ if (obj instanceof jQuery) {
144
+ this.assert(
145
+ obj.is(':empty')
146
+ , 'expected #{this} to be empty'
147
+ , 'expected #{this} not to be empty');
148
+ } else {
149
+ _super.apply(this, arguments);
150
+ }
151
+ };
152
+ });
153
+
136
154
  chai.Assertion.overwriteProperty('be', function (_super) {
137
155
  return function () {
138
156
  var be = function (selector) {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chai-jquery-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-02 00:00:00.000000000 Z
12
+ date: 2012-09-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
@@ -75,7 +75,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
75
75
  version: '0'
76
76
  segments:
77
77
  - 0
78
- hash: -954104846263079875
78
+ hash: -401249594129084681
79
79
  required_rubygems_version: !ruby/object:Gem::Requirement
80
80
  none: false
81
81
  requirements:
@@ -84,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
84
  version: '0'
85
85
  segments:
86
86
  - 0
87
- hash: -954104846263079875
87
+ hash: -401249594129084681
88
88
  requirements: []
89
89
  rubyforge_project:
90
90
  rubygems_version: 1.8.24