jquery_mockjax_rails 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +1 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +8 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +152 -0
- data/MIT-LICENSE +20 -0
- data/README.md +62 -0
- data/Rakefile +11 -0
- data/jquery_mockjax_rails.gemspec +26 -0
- data/lib/jquery_mockjax_rails.rb +8 -0
- data/lib/jquery_mockjax_rails/engine.rb +8 -0
- data/lib/jquery_mockjax_rails/helper.rb +7 -0
- data/lib/jquery_mockjax_rails/jquery_mockjax_middleware.rb +24 -0
- data/lib/jquery_mockjax_rails/jquery_mockjax_rails.rb +25 -0
- data/lib/jquery_mockjax_rails/rspec_integration.rb +9 -0
- data/lib/jquery_mockjax_rails/version.rb +3 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +15 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/controllers/home_controller.rb +4 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/views/home/index.html.erb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +65 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/test.rb +37 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +15 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +60 -0
- data/spec/dummy/lib/assets/.gitkeep +0 -0
- data/spec/dummy/log/.gitkeep +0 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/requests/assets_spec.rb +11 -0
- data/spec/requests/home_spec.rb +18 -0
- data/spec/spec_helper.rb +21 -0
- data/spec/support/capybara.rb +2 -0
- data/spec/support/integration_helper.rb +5 -0
- data/vendor/assets/javascripts/jquery.mockjax.js +580 -0
- metadata +192 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 484656b1d33f445475774fcf51569d621e67f379
|
|
4
|
+
data.tar.gz: da0ea89cf929f7bcebc9faf3f09ab4c19445183c
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: b4508b5524726318e6868aea1753b4be635e1900e8bcc265a94280076a4bc54e7a8b5480e4896fdc511491eccd16099182fabd26ec84382194565599a01d88b8
|
|
7
|
+
data.tar.gz: c453586bce5da77bddab1366061578287d9a63c487796dea281532e6e9c9bac708b03101dc78eeaa42285c03db8b1c8250b0a9c73ed413d6457a8a5bae73bd3a
|
data/.gitignore
ADDED
data/.rspec
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
-f d -c
|
data/.ruby-gemset
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
jquery_mockjax_rails
|
data/.ruby-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ruby-2.0.0-p247
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
jquery_mockjax_rails (0.0.1)
|
|
5
|
+
capybara (~> 2.0.0)
|
|
6
|
+
rails (~> 3.2.12)
|
|
7
|
+
rspec-rails (~> 2.13.0)
|
|
8
|
+
|
|
9
|
+
GEM
|
|
10
|
+
remote: http://rubygems.org/
|
|
11
|
+
specs:
|
|
12
|
+
actionmailer (3.2.13)
|
|
13
|
+
actionpack (= 3.2.13)
|
|
14
|
+
mail (~> 2.5.3)
|
|
15
|
+
actionpack (3.2.13)
|
|
16
|
+
activemodel (= 3.2.13)
|
|
17
|
+
activesupport (= 3.2.13)
|
|
18
|
+
builder (~> 3.0.0)
|
|
19
|
+
erubis (~> 2.7.0)
|
|
20
|
+
journey (~> 1.0.4)
|
|
21
|
+
rack (~> 1.4.5)
|
|
22
|
+
rack-cache (~> 1.2)
|
|
23
|
+
rack-test (~> 0.6.1)
|
|
24
|
+
sprockets (~> 2.2.1)
|
|
25
|
+
activemodel (3.2.13)
|
|
26
|
+
activesupport (= 3.2.13)
|
|
27
|
+
builder (~> 3.0.0)
|
|
28
|
+
activerecord (3.2.13)
|
|
29
|
+
activemodel (= 3.2.13)
|
|
30
|
+
activesupport (= 3.2.13)
|
|
31
|
+
arel (~> 3.0.2)
|
|
32
|
+
tzinfo (~> 0.3.29)
|
|
33
|
+
activeresource (3.2.13)
|
|
34
|
+
activemodel (= 3.2.13)
|
|
35
|
+
activesupport (= 3.2.13)
|
|
36
|
+
activesupport (3.2.13)
|
|
37
|
+
i18n (= 0.6.1)
|
|
38
|
+
multi_json (~> 1.0)
|
|
39
|
+
arel (3.0.2)
|
|
40
|
+
builder (3.0.4)
|
|
41
|
+
capybara (2.0.3)
|
|
42
|
+
mime-types (>= 1.16)
|
|
43
|
+
nokogiri (>= 1.3.3)
|
|
44
|
+
rack (>= 1.0.0)
|
|
45
|
+
rack-test (>= 0.5.4)
|
|
46
|
+
selenium-webdriver (~> 2.0)
|
|
47
|
+
xpath (~> 1.0.0)
|
|
48
|
+
childprocess (0.3.9)
|
|
49
|
+
ffi (~> 1.0, >= 1.0.11)
|
|
50
|
+
columnize (0.3.6)
|
|
51
|
+
debugger (1.6.0)
|
|
52
|
+
columnize (>= 0.3.1)
|
|
53
|
+
debugger-linecache (~> 1.2.0)
|
|
54
|
+
debugger-ruby_core_source (~> 1.2.1)
|
|
55
|
+
debugger-linecache (1.2.0)
|
|
56
|
+
debugger-ruby_core_source (1.2.3)
|
|
57
|
+
diff-lcs (1.2.4)
|
|
58
|
+
erubis (2.7.0)
|
|
59
|
+
eventmachine (1.0.3)
|
|
60
|
+
faye-websocket (0.4.7)
|
|
61
|
+
eventmachine (>= 0.12.0)
|
|
62
|
+
ffi (1.9.0)
|
|
63
|
+
hike (1.2.3)
|
|
64
|
+
http_parser.rb (0.5.3)
|
|
65
|
+
i18n (0.6.1)
|
|
66
|
+
journey (1.0.4)
|
|
67
|
+
jquery-rails (3.0.2)
|
|
68
|
+
railties (>= 3.0, < 5.0)
|
|
69
|
+
thor (>= 0.14, < 2.0)
|
|
70
|
+
json (1.8.0)
|
|
71
|
+
mail (2.5.4)
|
|
72
|
+
mime-types (~> 1.16)
|
|
73
|
+
treetop (~> 1.4.8)
|
|
74
|
+
mime-types (1.23)
|
|
75
|
+
mini_portile (0.5.0)
|
|
76
|
+
multi_json (1.7.7)
|
|
77
|
+
nokogiri (1.6.0)
|
|
78
|
+
mini_portile (~> 0.5.0)
|
|
79
|
+
poltergeist (1.1.2)
|
|
80
|
+
capybara (~> 2.0.1)
|
|
81
|
+
faye-websocket (~> 0.4.4)
|
|
82
|
+
http_parser.rb (~> 0.5.3)
|
|
83
|
+
polyglot (0.3.3)
|
|
84
|
+
rack (1.4.5)
|
|
85
|
+
rack-cache (1.2)
|
|
86
|
+
rack (>= 0.4)
|
|
87
|
+
rack-ssl (1.3.3)
|
|
88
|
+
rack
|
|
89
|
+
rack-test (0.6.2)
|
|
90
|
+
rack (>= 1.0)
|
|
91
|
+
rails (3.2.13)
|
|
92
|
+
actionmailer (= 3.2.13)
|
|
93
|
+
actionpack (= 3.2.13)
|
|
94
|
+
activerecord (= 3.2.13)
|
|
95
|
+
activeresource (= 3.2.13)
|
|
96
|
+
activesupport (= 3.2.13)
|
|
97
|
+
bundler (~> 1.0)
|
|
98
|
+
railties (= 3.2.13)
|
|
99
|
+
railties (3.2.13)
|
|
100
|
+
actionpack (= 3.2.13)
|
|
101
|
+
activesupport (= 3.2.13)
|
|
102
|
+
rack-ssl (~> 1.3.2)
|
|
103
|
+
rake (>= 0.8.7)
|
|
104
|
+
rdoc (~> 3.4)
|
|
105
|
+
thor (>= 0.14.6, < 2.0)
|
|
106
|
+
rake (10.1.0)
|
|
107
|
+
rdoc (3.12.2)
|
|
108
|
+
json (~> 1.4)
|
|
109
|
+
rspec-core (2.13.1)
|
|
110
|
+
rspec-expectations (2.13.0)
|
|
111
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
|
112
|
+
rspec-mocks (2.13.1)
|
|
113
|
+
rspec-rails (2.13.2)
|
|
114
|
+
actionpack (>= 3.0)
|
|
115
|
+
activesupport (>= 3.0)
|
|
116
|
+
railties (>= 3.0)
|
|
117
|
+
rspec-core (~> 2.13.0)
|
|
118
|
+
rspec-expectations (~> 2.13.0)
|
|
119
|
+
rspec-mocks (~> 2.13.0)
|
|
120
|
+
rubyzip (0.9.9)
|
|
121
|
+
selenium-webdriver (2.33.0)
|
|
122
|
+
childprocess (>= 0.2.5)
|
|
123
|
+
multi_json (~> 1.0)
|
|
124
|
+
rubyzip
|
|
125
|
+
websocket (~> 1.0.4)
|
|
126
|
+
spring (0.0.10)
|
|
127
|
+
sprockets (2.2.2)
|
|
128
|
+
hike (~> 1.2)
|
|
129
|
+
multi_json (~> 1.0)
|
|
130
|
+
rack (~> 1.0)
|
|
131
|
+
tilt (~> 1.1, != 1.3.0)
|
|
132
|
+
sqlite3 (1.3.7)
|
|
133
|
+
thor (0.18.1)
|
|
134
|
+
tilt (1.4.1)
|
|
135
|
+
treetop (1.4.14)
|
|
136
|
+
polyglot
|
|
137
|
+
polyglot (>= 0.3.1)
|
|
138
|
+
tzinfo (0.3.37)
|
|
139
|
+
websocket (1.0.7)
|
|
140
|
+
xpath (1.0.0)
|
|
141
|
+
nokogiri (~> 1.3)
|
|
142
|
+
|
|
143
|
+
PLATFORMS
|
|
144
|
+
ruby
|
|
145
|
+
|
|
146
|
+
DEPENDENCIES
|
|
147
|
+
debugger
|
|
148
|
+
jquery-rails
|
|
149
|
+
jquery_mockjax_rails!
|
|
150
|
+
poltergeist
|
|
151
|
+
spring
|
|
152
|
+
sqlite3
|
data/MIT-LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright 2013 ThachChau
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
'Software'), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# jquery_mockjax_rails
|
|
2
|
+
|
|
3
|
+
[](https://travis-ci.org/chautoni/jquery_mockjax_rails)
|
|
4
|
+
|
|
5
|
+
This gem provides:
|
|
6
|
+
|
|
7
|
+
* [jQuery Mockjax 1.5.2](https://github.com/appendto/jquery-mockjax)
|
|
8
|
+
* Ajax mocking helper in your Rspec integration tests
|
|
9
|
+
|
|
10
|
+
## Requirements
|
|
11
|
+
|
|
12
|
+
* Rails 3.1 or later
|
|
13
|
+
* Assets pipeline enabled
|
|
14
|
+
* jQuery
|
|
15
|
+
* Rspec/Capybara integration tests
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
Add the `jquery_mockjax_rails` gem to your Gemfile
|
|
20
|
+
|
|
21
|
+
```ruby
|
|
22
|
+
group :test do
|
|
23
|
+
gem 'jquery_mockjax_rails'
|
|
24
|
+
end
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
And run `bundle install`
|
|
28
|
+
|
|
29
|
+
## Getting Started
|
|
30
|
+
|
|
31
|
+
Stub the ajax request in a `before` block
|
|
32
|
+
|
|
33
|
+
```ruby
|
|
34
|
+
describe 'My integration spec', js: true do
|
|
35
|
+
|
|
36
|
+
before do
|
|
37
|
+
stub_ajax url: '/api/path', responseText: { message: 'message' }
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Once the browser has been lauched, open the JS console and test the mocked response
|
|
43
|
+
|
|
44
|
+
```coffeescript
|
|
45
|
+
$.getJSON('/api/path', function(data) { console.log(data.message) }); # => message
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Acknowledgements
|
|
49
|
+
|
|
50
|
+
The original idea has come from [ejholmes](https://github.com/ejholmes/mockjax), however, the gem has been deprecated and does not work with current Rails 3 application using rspec/capybara integration test, so I've decided to re-write the gem from scratch.
|
|
51
|
+
Most of the core code pieces have been emerged from [ejholmes](https://github.com/ejholmes/mockjax)'s work.
|
|
52
|
+
|
|
53
|
+
## Contributing
|
|
54
|
+
|
|
55
|
+
Pull requests are more than welcome. Before submitting pull requests, please make sure your changes are covered with tests.
|
|
56
|
+
|
|
57
|
+
For testing purpose, please create a dummy `test.sqlite3` when running tests for the first time
|
|
58
|
+
|
|
59
|
+
```sh
|
|
60
|
+
mkdir spec/dummy/db
|
|
61
|
+
touch spec/dummy/db/test.sqlite3
|
|
62
|
+
```
|
data/Rakefile
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
$:.push File.expand_path('../lib', __FILE__)
|
|
2
|
+
|
|
3
|
+
# Maintain your gem's version:
|
|
4
|
+
require 'jquery_mockjax_rails/version'
|
|
5
|
+
|
|
6
|
+
# Describe your gem and declare its dependencies:
|
|
7
|
+
Gem::Specification.new do |s|
|
|
8
|
+
s.name = 'jquery_mockjax_rails'
|
|
9
|
+
s.version = JqueryMockjaxRails::VERSION
|
|
10
|
+
s.authors = ['Thach Chau']
|
|
11
|
+
s.email = ['rog.kane@gmail.com']
|
|
12
|
+
s.homepage = 'http://github.com/chautoni'
|
|
13
|
+
s.summary = 'Use jquery.mockjax in RSpec with Rails 3'
|
|
14
|
+
s.description = 'This gem provides jQuery Mockjax support in Rspec integration testing with Capybara'
|
|
15
|
+
|
|
16
|
+
s.files = `git ls-files`.split("\n")
|
|
17
|
+
s.require_path = 'lib'
|
|
18
|
+
|
|
19
|
+
s.add_dependency 'rails', '~> 3.2.12'
|
|
20
|
+
s.add_dependency 'rspec-rails', '~> 2.13.0'
|
|
21
|
+
s.add_dependency 'capybara', '~> 2.0.0'
|
|
22
|
+
s.add_development_dependency 'sqlite3'
|
|
23
|
+
s.add_development_dependency 'debugger'
|
|
24
|
+
s.add_development_dependency 'spring'
|
|
25
|
+
s.add_development_dependency 'poltergeist'
|
|
26
|
+
end
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
require 'jquery_mockjax_rails/engine'
|
|
2
|
+
require 'jquery_mockjax_rails/helper'
|
|
3
|
+
require 'jquery_mockjax_rails/rspec_integration'
|
|
4
|
+
require 'jquery_mockjax_rails/jquery_mockjax_rails'
|
|
5
|
+
require 'jquery_mockjax_rails/jquery_mockjax_middleware'
|
|
6
|
+
|
|
7
|
+
module JqueryMockjaxRails
|
|
8
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
class JqueryMockjaxMiddleware
|
|
2
|
+
def initialize app
|
|
3
|
+
@app = app
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
def call env
|
|
7
|
+
status, headers, response = @app.call(env)
|
|
8
|
+
append_mockjaxes response
|
|
9
|
+
[status, headers, response]
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
private
|
|
13
|
+
def append_mockjaxes response
|
|
14
|
+
if response.is_a? ActionDispatch::Response
|
|
15
|
+
response.body = response.body.gsub!(
|
|
16
|
+
/(<\/head>)/,
|
|
17
|
+
%Q{
|
|
18
|
+
<script src='#{JqueryMockjaxRails.js_path}' type='text/javascript'></script>
|
|
19
|
+
<script type='text/javascript'>#{JqueryMockjaxRails.js_output}</script>\\1
|
|
20
|
+
}.squish
|
|
21
|
+
)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module JqueryMockjaxRails
|
|
2
|
+
class << self
|
|
3
|
+
def stub args
|
|
4
|
+
stubs << args
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def stubs
|
|
8
|
+
@stubs ||= []
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def clean
|
|
12
|
+
stubs = []
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def js_path
|
|
16
|
+
@js_path ||= '/assets/jquery.mockjax.js'
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def js_output
|
|
20
|
+
stubs.inject('') do |result, stub|
|
|
21
|
+
"#{result}jQuery.mockjax(#{stub.to_json})\n"
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
data/spec/dummy/Rakefile
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
#!/usr/bin/env rake
|
|
2
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
|
3
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
|
4
|
+
|
|
5
|
+
require File.expand_path('../config/application', __FILE__)
|
|
6
|
+
|
|
7
|
+
Dummy::Application.load_tasks
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
|
2
|
+
// listed below.
|
|
3
|
+
//
|
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
|
6
|
+
//
|
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
|
8
|
+
// the compiled file.
|
|
9
|
+
//
|
|
10
|
+
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
|
|
11
|
+
// GO AFTER THE REQUIRES BELOW.
|
|
12
|
+
//
|
|
13
|
+
//= require jquery
|
|
14
|
+
//= require jquery_ujs
|
|
15
|
+
//= require_tree .
|