chai-jquery-rails 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.gitmodules ADDED
@@ -0,0 +1,3 @@
1
+ [submodule "chai-jquery"]
2
+ path = chai-jquery
3
+ url = https://github.com/chaijs/chai-jquery
data/.rvmrc ADDED
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
7
+ # Only full ruby name is supported here, for short names use:
8
+ # echo "rvm use 1.9.3" > .rvmrc
9
+ environment_id="ruby-1.9.3-p194@chai-jquery-rails"
10
+
11
+ # Uncomment the following lines if you want to verify rvm version per project
12
+ # rvmrc_rvm_version="1.14.2 ()" # 1.10.1 seams as a safe start
13
+ # eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
14
+ # echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
15
+ # return 1
16
+ # }
17
+
18
+ # First we attempt to load the desired environment directly from the environment
19
+ # file. This is very fast and efficient compared to running through the entire
20
+ # CLI and selector. If you want feedback on which environment was used then
21
+ # insert the word 'use' after --create as this triggers verbose mode.
22
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
23
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
24
+ then
25
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
26
+ [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
27
+ \. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
28
+ if [[ $- == *i* ]] # check for interactive shells
29
+ then echo "Using: $(tput setaf 2)$GEM_HOME$(tput sgr0)" # show the user the ruby and gemset they are using in green
30
+ else echo "Using: $GEM_HOME" # don't use colors in non-interactive shells
31
+ fi
32
+ else
33
+ # If the environment file has not yet been created, use the RVM CLI to select.
34
+ rvm --create use "$environment_id" || {
35
+ echo "Failed to create RVM environment '${environment_id}'."
36
+ return 1
37
+ }
38
+ fi
39
+
40
+ # If you use bundler, this might be useful to you:
41
+ # if [[ -s Gemfile ]] && {
42
+ # ! builtin command -v bundle >/dev/null ||
43
+ # builtin command -v bundle | GREP_OPTIONS= \grep $rvm_path/bin/bundle >/dev/null
44
+ # }
45
+ # then
46
+ # printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
47
+ # gem install bundler
48
+ # fi
49
+ # if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
50
+ # then
51
+ # bundle install | GREP_OPTIONS= \grep -vE '^Using|Your bundle is complete'
52
+ # fi
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in chai-jquery-rails.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Christian Schlensker
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,46 @@
1
+ # Chai jQuery Rails
2
+
3
+ [chai-jquery](https://github.com/chaijs/chai-jquery) is a plugin for
4
+ [chai](http://chaijs.com/) that gives you jquery expectation helpers.
5
+
6
+ This is a simple gem that adds chai-jquery to rails asset pipline.
7
+
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ group :development, :test do
14
+ gem 'chai-jquery-rails'
15
+ end
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+
22
+ Then in your test files add a sprocket require statement:
23
+
24
+ js: `//= require chai-jquery`
25
+
26
+ coffeescript: `#= require chai-jquery`
27
+
28
+ This gem also depends on [chai](http://chaijs.com/) which in turn depends on
29
+ [mocha](http://visionmedia.github.com/mocha/).
30
+ The best way to get those is with the
31
+ [konacha gem](https://github.com/jfirebaugh/konacha).
32
+
33
+ ## Kudos
34
+
35
+ - [chai-jquery](https://github.com/chaijs/chai-jquery) for doing the hard work.
36
+ - [Derek Prior](http://prioritized.net/blog/gemify-assets-for-rails/) for
37
+ blogging about how to write a gem that includes rails assets.
38
+
39
+
40
+ ## Contributing
41
+
42
+ 1. Fork it
43
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
44
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
45
+ 4. Push to the branch (`git push origin my-new-feature`)
46
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ task :assets do
5
+ sh 'git submodule update --init'
6
+ mkdir_p 'vendor/assets/javascripts'
7
+ cp 'chai-jquery/chai-jquery.js', 'vendor/assets/javascripts/'
8
+ end
@@ -0,0 +1,18 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/chai-jquery-rails/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Christian Schlensker"]
6
+ gem.email = ["christian@cswebartisan.com"]
7
+ gem.description = %q{Adds chai-jquery plugin to rails asset pipeline}
8
+ gem.summary = %q{The chai jquery plugin adds jquery related helpers to the chai expectation library}
9
+ gem.homepage = "https://github.com/wordofchristian/chai-jquery-rails"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.name = "chai-jquery-rails"
13
+ gem.require_paths = ["lib"]
14
+ gem.version = Chai::Jquery::Rails::VERSION
15
+
16
+ gem.add_dependency "railties", "~> 3.1"
17
+ gem.add_dependency "sprockets"
18
+ end
@@ -0,0 +1,10 @@
1
+ require "chai-jquery-rails/version"
2
+
3
+ module Chai
4
+ module Jquery
5
+ module Rails
6
+ class Engine < ::Rails::Engine
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ module Chai
2
+ module Jquery
3
+ module Rails
4
+ VERSION = "0.0.2"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,214 @@
1
+ (function (chaiJquery) {
2
+ // Module systems magic dance.
3
+ if (typeof require === "function" && typeof exports === "object" && typeof module === "object") {
4
+ // NodeJS
5
+ module.exports = chaiJquery;
6
+ } else if (typeof define === "function" && define.amd) {
7
+ // AMD
8
+ define(function () {
9
+ return chaiJquery;
10
+ });
11
+ } else {
12
+ // Other environment (usually <script> tag): pass into global chai
13
+ var global = (false || eval)("this");
14
+ global.chai.use(chaiJquery);
15
+ }
16
+ }(function (chai, utils) {
17
+ var inspect = utils.inspect,
18
+ flag = utils.flag;
19
+
20
+ jQuery.fn.inspect = function (depth) {
21
+ var el = jQuery('<div />').append(this.clone());
22
+ if (depth) {
23
+ var children = el.children();
24
+ while (depth-- > 0)
25
+ children = children.children();
26
+ children.html('...');
27
+ }
28
+ return el.html();
29
+ };
30
+
31
+ chai.Assertion.addMethod('attr', function (name, val) {
32
+ var actual = flag(this, 'object').attr(name);
33
+
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
+ }
42
+
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
+ }
52
+
53
+ flag(this, 'object', actual);
54
+ });
55
+
56
+ chai.Assertion.addMethod('data', function (name, val) {
57
+ // Work around a chai bug (https://github.com/logicalparadox/chai/issues/16)
58
+ if (flag(this, 'negate') && undefined !== val && undefined === flag(this, 'object').data(name)) {
59
+ return;
60
+ }
61
+
62
+ var assertion = new chai.Assertion(flag(this, 'object').data());
63
+ if (flag(this, 'negate'))
64
+ assertion = assertion.not;
65
+ assertion.property(name, val);
66
+ });
67
+
68
+ chai.Assertion.addMethod('class', function (className) {
69
+ this.assert(
70
+ flag(this, 'object').hasClass(className)
71
+ , 'expected #{this} to have class #{exp}'
72
+ , 'expected #{this} not to have class #{exp}'
73
+ , className
74
+ );
75
+ });
76
+
77
+ chai.Assertion.addMethod('id', function (id) {
78
+ this.assert(
79
+ flag(this, 'object').attr('id') === id
80
+ , 'expected #{this} to have id #{exp}'
81
+ , 'expected #{this} not to have id #{exp}'
82
+ , id
83
+ );
84
+ });
85
+
86
+ chai.Assertion.addMethod('html', function (html) {
87
+ this.assert(
88
+ flag(this, 'object').html() === html
89
+ , 'expected #{this} to have HTML #{exp}'
90
+ , 'expected #{this} not to have HTML #{exp}'
91
+ , html
92
+ );
93
+ });
94
+
95
+ chai.Assertion.addMethod('text', function (text) {
96
+ this.assert(
97
+ flag(this, 'object').text() === text
98
+ , 'expected #{this} to have text #{exp}'
99
+ , 'expected #{this} not to have text #{exp}'
100
+ , text
101
+ );
102
+ });
103
+
104
+ chai.Assertion.addMethod('value', function (value) {
105
+ this.assert(
106
+ flag(this, 'object').val() === value
107
+ , 'expected #{this} to have value #{exp}'
108
+ , 'expected #{this} not to have value #{exp}'
109
+ , value
110
+ );
111
+ });
112
+
113
+ jQuery.each(['visible', 'hidden', 'selected', 'checked', 'disabled'], function (i, attr) {
114
+ chai.Assertion.addProperty(attr, function () {
115
+ this.assert(
116
+ flag(this, 'object').is(':' + attr)
117
+ , 'expected #{this} to be ' + attr
118
+ , 'expected #{this} not to be ' + attr);
119
+ });
120
+ });
121
+
122
+ chai.Assertion.overwriteProperty('exist', function (_super) {
123
+ return function () {
124
+ var obj = flag(this, 'object');
125
+ if (obj instanceof jQuery) {
126
+ this.assert(
127
+ obj.length > 0
128
+ , 'expected ' + inspect(obj.selector) + ' to exist'
129
+ , 'expected ' + inspect(obj.selector) + ' not to exist');
130
+ } else {
131
+ _super.apply(this, arguments);
132
+ }
133
+ };
134
+ });
135
+
136
+ chai.Assertion.overwriteProperty('be', function (_super) {
137
+ return function () {
138
+ var be = function (selector) {
139
+ var obj = flag(this, 'object');
140
+ if (obj instanceof jQuery) {
141
+ this.assert(
142
+ obj.is(selector)
143
+ , 'expected #{this} to be #{exp}'
144
+ , 'expected #{this} not to be #{exp}'
145
+ , selector
146
+ );
147
+ } else {
148
+ _super.apply(this, arguments);
149
+ }
150
+ };
151
+ be.__proto__ = this;
152
+ return be;
153
+ }
154
+ });
155
+
156
+ chai.Assertion.overwriteMethod('match', function (_super) {
157
+ return function (selector) {
158
+ var obj = flag(this, 'object');
159
+ if (obj instanceof jQuery) {
160
+ this.assert(
161
+ obj.is(selector)
162
+ , 'expected #{this} to match #{exp}'
163
+ , 'expected #{this} not to match #{exp}'
164
+ , selector
165
+ );
166
+ } else {
167
+ _super.apply(this, arguments);
168
+ }
169
+ }
170
+ });
171
+
172
+ chai.Assertion.overwriteProperty('contain', function (_super) {
173
+ return function () {
174
+ _super.call(this);
175
+ var contain = function (text) {
176
+ var obj = flag(this, 'object');
177
+ if (obj instanceof jQuery) {
178
+ this.assert(
179
+ obj.is(':contains(\'' + text + '\')')
180
+ , 'expected #{this} to contain #{exp}'
181
+ , 'expected #{this} not to contain #{exp}'
182
+ , text
183
+ );
184
+ } else {
185
+ Function.prototype.apply.call(_super.call(this), this, arguments);
186
+ }
187
+ };
188
+ contain.__proto__ = this;
189
+ return contain;
190
+ }
191
+ });
192
+
193
+ chai.Assertion.overwriteProperty('have', function (_super) {
194
+ return function () {
195
+ var obj = flag(this, 'object');
196
+ if (obj instanceof jQuery) {
197
+ var have = function (selector) {
198
+ this.assert(
199
+ // Using find() rather than has() to work around a jQuery bug:
200
+ // http://bugs.jquery.com/ticket/11706
201
+ obj.find(selector).length > 0
202
+ , 'expected #{this} to have #{exp}'
203
+ , 'expected #{this} not to have #{exp}'
204
+ , selector
205
+ );
206
+ };
207
+ have.__proto__ = this;
208
+ return have;
209
+ } else {
210
+ _super.call(this);
211
+ }
212
+ }
213
+ });
214
+ }));
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chai-jquery-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Christian Schlensker
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: railties
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.1'
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: '3.1'
30
+ - !ruby/object:Gem::Dependency
31
+ name: sprockets
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
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
+ description: Adds chai-jquery plugin to rails asset pipeline
47
+ email:
48
+ - christian@cswebartisan.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - .gitmodules
55
+ - .rvmrc
56
+ - Gemfile
57
+ - LICENSE
58
+ - README.md
59
+ - Rakefile
60
+ - chai-jquery-rails.gemspec
61
+ - lib/chai-jquery-rails.rb
62
+ - lib/chai-jquery-rails/version.rb
63
+ - vendor/assets/javascripts/chai-jquery.js
64
+ homepage: https://github.com/wordofchristian/chai-jquery-rails
65
+ licenses: []
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ segments:
77
+ - 0
78
+ hash: -954104846263079875
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ segments:
86
+ - 0
87
+ hash: -954104846263079875
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 1.8.24
91
+ signing_key:
92
+ specification_version: 3
93
+ summary: The chai jquery plugin adds jquery related helpers to the chai expectation
94
+ library
95
+ test_files: []