simple_javascript_testing 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +89 -0
- data/README.md +4 -0
- data/app/views/layouts/application.html.erb +0 -0
- data/app/views/users/index.html.erb +0 -0
- data/index.js +58 -0
- data/lib/simple_javascript_testing.rb +52 -0
- data/lib/stub_ajax.js +23 -0
- data/package.json +25 -0
- data/simple_javascript_testing.gemspec +17 -0
- data/test/html/users/index.html +0 -0
- data/test/javascript/users/index.js +0 -0
- data/test/simple_javascript_testing_test.rb +35 -0
- metadata +71 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 85a7a2f6974dc9ffc11dda6b0718aadebb0de710
|
4
|
+
data.tar.gz: c2275e6e54937e7cc005cb3599eca1b42189b660
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ff3e7dcc061ffa6391d6b2e185aa7c2fa6f4d6142b96d35a86642a92770230e7b8e44df0e26df2d6e23c94eb967b36089cf4ab8d93eb0afce8a53cb39ee538c1
|
7
|
+
data.tar.gz: e4cc075c93af14bf1c0de7da7f260406210cbd6662a7e8a32a5efa4bcca0113f6d5a767b3f27eaf95cb32e05f9158d84a7cc175c672b96d109f7d8a6fd26e9a7
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
simple_javascript_testing (0.0.1)
|
5
|
+
rails (>= 3.0.7)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
actionmailer (4.1.6)
|
11
|
+
actionpack (= 4.1.6)
|
12
|
+
actionview (= 4.1.6)
|
13
|
+
mail (~> 2.5, >= 2.5.4)
|
14
|
+
actionpack (4.1.6)
|
15
|
+
actionview (= 4.1.6)
|
16
|
+
activesupport (= 4.1.6)
|
17
|
+
rack (~> 1.5.2)
|
18
|
+
rack-test (~> 0.6.2)
|
19
|
+
actionview (4.1.6)
|
20
|
+
activesupport (= 4.1.6)
|
21
|
+
builder (~> 3.1)
|
22
|
+
erubis (~> 2.7.0)
|
23
|
+
activemodel (4.1.6)
|
24
|
+
activesupport (= 4.1.6)
|
25
|
+
builder (~> 3.1)
|
26
|
+
activerecord (4.1.6)
|
27
|
+
activemodel (= 4.1.6)
|
28
|
+
activesupport (= 4.1.6)
|
29
|
+
arel (~> 5.0.0)
|
30
|
+
activesupport (4.1.6)
|
31
|
+
i18n (~> 0.6, >= 0.6.9)
|
32
|
+
json (~> 1.7, >= 1.7.7)
|
33
|
+
minitest (~> 5.1)
|
34
|
+
thread_safe (~> 0.1)
|
35
|
+
tzinfo (~> 1.1)
|
36
|
+
arel (5.0.1.20140414130214)
|
37
|
+
builder (3.2.2)
|
38
|
+
erubis (2.7.0)
|
39
|
+
hike (1.2.3)
|
40
|
+
i18n (0.6.11)
|
41
|
+
json (1.8.1)
|
42
|
+
mail (2.6.1)
|
43
|
+
mime-types (>= 1.16, < 3)
|
44
|
+
mime-types (2.4.3)
|
45
|
+
minitest (5.4.2)
|
46
|
+
multi_json (1.10.1)
|
47
|
+
rack (1.5.2)
|
48
|
+
rack-test (0.6.2)
|
49
|
+
rack (>= 1.0)
|
50
|
+
rails (4.1.6)
|
51
|
+
actionmailer (= 4.1.6)
|
52
|
+
actionpack (= 4.1.6)
|
53
|
+
actionview (= 4.1.6)
|
54
|
+
activemodel (= 4.1.6)
|
55
|
+
activerecord (= 4.1.6)
|
56
|
+
activesupport (= 4.1.6)
|
57
|
+
bundler (>= 1.3.0, < 2.0)
|
58
|
+
railties (= 4.1.6)
|
59
|
+
sprockets-rails (~> 2.0)
|
60
|
+
railties (4.1.6)
|
61
|
+
actionpack (= 4.1.6)
|
62
|
+
activesupport (= 4.1.6)
|
63
|
+
rake (>= 0.8.7)
|
64
|
+
thor (>= 0.18.1, < 2.0)
|
65
|
+
rake (10.3.2)
|
66
|
+
render_anywhere (0.0.9)
|
67
|
+
rails (>= 3.0.7)
|
68
|
+
sprockets (2.12.0)
|
69
|
+
hike (~> 1.2)
|
70
|
+
multi_json (~> 1.0)
|
71
|
+
rack (~> 1.0)
|
72
|
+
tilt (~> 1.1, != 1.3.0)
|
73
|
+
sprockets-rails (2.2.0)
|
74
|
+
actionpack (>= 3.0)
|
75
|
+
activesupport (>= 3.0)
|
76
|
+
sprockets (>= 2.8, < 4.0)
|
77
|
+
thor (0.19.1)
|
78
|
+
thread_safe (0.3.4)
|
79
|
+
tilt (1.4.1)
|
80
|
+
tzinfo (1.2.2)
|
81
|
+
thread_safe (~> 0.1)
|
82
|
+
|
83
|
+
PLATFORMS
|
84
|
+
ruby
|
85
|
+
|
86
|
+
DEPENDENCIES
|
87
|
+
rails
|
88
|
+
render_anywhere
|
89
|
+
simple_javascript_testing!
|
data/README.md
ADDED
File without changes
|
File without changes
|
data/index.js
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
var system = require('system')
|
2
|
+
var args = system.args
|
3
|
+
|
4
|
+
if (!Function.prototype.bind) {
|
5
|
+
Function.prototype.bind = function(oThis) {
|
6
|
+
if (typeof this !== 'function') {
|
7
|
+
// closest thing possible to the ECMAScript 5
|
8
|
+
// internal IsCallable function
|
9
|
+
throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable');
|
10
|
+
}
|
11
|
+
|
12
|
+
var aArgs = Array.prototype.slice.call(arguments, 1),
|
13
|
+
fToBind = this,
|
14
|
+
fNOP = function() {},
|
15
|
+
fBound = function() {
|
16
|
+
return fToBind.apply(this instanceof fNOP && oThis
|
17
|
+
? this
|
18
|
+
: oThis,
|
19
|
+
aArgs.concat(Array.prototype.slice.call(arguments)));
|
20
|
+
};
|
21
|
+
|
22
|
+
fNOP.prototype = this.prototype;
|
23
|
+
fBound.prototype = new fNOP();
|
24
|
+
|
25
|
+
return fBound;
|
26
|
+
};
|
27
|
+
}
|
28
|
+
|
29
|
+
if (args.length === 1) {
|
30
|
+
console.log('Try to pass some arguments when invoking this script!');
|
31
|
+
phantom.exit()
|
32
|
+
}
|
33
|
+
|
34
|
+
var page = require('webpage').create()
|
35
|
+
page.onConsoleMessage = function(msg, lineNum, sourceId) {
|
36
|
+
console.log('CONSOLE: ' + msg ) //' (from line #' + lineNum + ' in "' + sourceId + '")');
|
37
|
+
}
|
38
|
+
|
39
|
+
var testObject = {
|
40
|
+
assert_equal: function(a, b){
|
41
|
+
if (a != b){
|
42
|
+
console.log("assertion failed:", a, "not equal to", b)
|
43
|
+
}
|
44
|
+
}
|
45
|
+
}
|
46
|
+
|
47
|
+
exports.runTest = function(name, test){
|
48
|
+
page.open("file:///" + args[1], function(status){
|
49
|
+
try{
|
50
|
+
test.bind(testObject)(page)
|
51
|
+
console.log("test succeeded: " + name)
|
52
|
+
} catch(e){
|
53
|
+
console.log(e.stack)
|
54
|
+
console.log("test failed: " + name)
|
55
|
+
}
|
56
|
+
phantom.exit()
|
57
|
+
})
|
58
|
+
}
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'render_anywhere'
|
3
|
+
|
4
|
+
class AnyClass
|
5
|
+
include RenderAnywhere
|
6
|
+
|
7
|
+
class << self
|
8
|
+
attr_accessor :prefix
|
9
|
+
end
|
10
|
+
|
11
|
+
def build_html(template)
|
12
|
+
html = render :template => template,
|
13
|
+
:layout => 'application'
|
14
|
+
html
|
15
|
+
end
|
16
|
+
# Include an additional helper
|
17
|
+
# If being used in a rake task, you may need to require the file(s)
|
18
|
+
# Ex: require Rails.root.join('app', 'helpers', 'blog_pages_helper')
|
19
|
+
def include_helper(helper_name)
|
20
|
+
set_render_anywhere_helpers(helper_name)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Apply an instance variable to the controller
|
24
|
+
# If you need to use instance variables instead of locals, just call this method as many times as you need.
|
25
|
+
def set_instance_variable_to(var, value)
|
26
|
+
set_instance_variable(var, value)
|
27
|
+
end
|
28
|
+
|
29
|
+
class RenderingController < RenderAnywhere::RenderingController
|
30
|
+
# include custom modules here, define accessors, etc. For example:
|
31
|
+
attr_accessor :current_user
|
32
|
+
helper_method :current_user
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
module SimpleJavascriptTesting
|
37
|
+
def call_template_with_js(template, &block)
|
38
|
+
data = AnyClass.new
|
39
|
+
if block_given?
|
40
|
+
yield data
|
41
|
+
end
|
42
|
+
FileUtils.mkdir_p("test/html/#{File.dirname template}")
|
43
|
+
FileUtils.mkdir_p("test/javascript/#{File.dirname template}")
|
44
|
+
html = data.build_html(template)
|
45
|
+
html.gsub!("<head>", "<head><script src='#{File.expand_path('node_modules')}/simple_javascript_testing/lib/stub_ajax.js'></script>")
|
46
|
+
html.gsub!("<script src='#{AnyClass.prefix}", "<script src='#{File.expand_path('public')}")
|
47
|
+
File.write("test/html/#{template}.html", html)
|
48
|
+
thing = "#{File.expand_path('html', 'test')}/#{template}"
|
49
|
+
thing2 = "#{File.expand_path('javascript', 'test')}/#{template}"
|
50
|
+
system "phantomjs #{thing2}.js #{thing}.html"
|
51
|
+
end
|
52
|
+
end
|
data/lib/stub_ajax.js
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
var all_requests = {}
|
2
|
+
var all_requests_length = 0
|
3
|
+
|
4
|
+
XMLHttpRequest.prototype.open = function(method, url){
|
5
|
+
all_requests_length += 1
|
6
|
+
all_requests[url] = {onload: this.onload}
|
7
|
+
}
|
8
|
+
|
9
|
+
function triggerRequest(url, data){
|
10
|
+
var request = all_requests[url]
|
11
|
+
all_requests_length -= 1
|
12
|
+
request.response = JSON.stringify(data)
|
13
|
+
request.status = 200
|
14
|
+
request.onload(request)
|
15
|
+
}
|
16
|
+
|
17
|
+
function assertAllRequestsRun(){
|
18
|
+
if (all_requests_length != 0){
|
19
|
+
throw("some requests not called")
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
23
|
+
XMLHttpRequest.prototype.send = function(){ }
|
data/package.json
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
{
|
2
|
+
"name": "simple_javascript_testing",
|
3
|
+
"version": "0.0.2",
|
4
|
+
"description": "simple javascript testing for rails",
|
5
|
+
"main": "index.js",
|
6
|
+
"scripts": {
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
8
|
+
},
|
9
|
+
"repository": {
|
10
|
+
"type": "git",
|
11
|
+
"url": "https://github.com/towski/simple_javascript_testing.git"
|
12
|
+
},
|
13
|
+
"keywords": [
|
14
|
+
"simple",
|
15
|
+
"javascript",
|
16
|
+
"testing",
|
17
|
+
"rails"
|
18
|
+
],
|
19
|
+
"author": "towski",
|
20
|
+
"license": "ISC",
|
21
|
+
"bugs": {
|
22
|
+
"url": "https://github.com/towski/simple_javascript_testing/issues"
|
23
|
+
},
|
24
|
+
"homepage": "https://github.com/towski/simple_javascript_testing"
|
25
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'simple_javascript_testing'
|
3
|
+
s.version = '0.0.1'
|
4
|
+
s.date = '2014-10-31'
|
5
|
+
s.summary = "Simple Javascript Testing"
|
6
|
+
s.description = "simple javascript testing for rails with phantomjs"
|
7
|
+
s.authors = ["towski"]
|
8
|
+
s.email = 'towski@gmail.com'
|
9
|
+
s.homepage = 'http://rubygems.org/gems/simple_javascript_testing'
|
10
|
+
s.license = 'MIT'
|
11
|
+
s.files = `git ls-files`.split("\n")
|
12
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
13
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
14
|
+
s.require_paths = ["lib"]
|
15
|
+
|
16
|
+
s.add_dependency('rails', '>= 3.0.7')
|
17
|
+
end
|
File without changes
|
File without changes
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'minitest/autorun'
|
3
|
+
require 'action_controller'
|
4
|
+
require 'simple_javascript_testing'
|
5
|
+
|
6
|
+
require 'rails/all'
|
7
|
+
|
8
|
+
# Require the gems listed in Gemfile, including any gems
|
9
|
+
# you've limited to :test, :development, or :production.
|
10
|
+
Bundler.require(*Rails.groups)
|
11
|
+
|
12
|
+
class SomeApplication < Rails::Application
|
13
|
+
end
|
14
|
+
|
15
|
+
module ApplicationHelper
|
16
|
+
end
|
17
|
+
|
18
|
+
class ApplicationController < ActionController::Base
|
19
|
+
end
|
20
|
+
|
21
|
+
Rails.application.initialize!
|
22
|
+
|
23
|
+
SharedTestRoutes = ActionDispatch::Routing::RouteSet.new
|
24
|
+
@routes = SharedTestRoutes
|
25
|
+
|
26
|
+
@routes.draw do
|
27
|
+
get ':controller(/:action)'
|
28
|
+
end
|
29
|
+
|
30
|
+
class SimpleJavascriptTestingTest < Minitest::Test
|
31
|
+
include SimpleJavascriptTesting
|
32
|
+
def test_call_template_with_js
|
33
|
+
call_template_with_js "users/index"
|
34
|
+
end
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simple_javascript_testing
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- towski
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.0.7
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.0.7
|
27
|
+
description: simple javascript testing for rails with phantomjs
|
28
|
+
email: towski@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- .gitignore
|
34
|
+
- Gemfile
|
35
|
+
- Gemfile.lock
|
36
|
+
- README.md
|
37
|
+
- app/views/layouts/application.html.erb
|
38
|
+
- app/views/users/index.html.erb
|
39
|
+
- index.js
|
40
|
+
- lib/simple_javascript_testing.rb
|
41
|
+
- lib/stub_ajax.js
|
42
|
+
- package.json
|
43
|
+
- simple_javascript_testing.gemspec
|
44
|
+
- test/html/users/index.html
|
45
|
+
- test/javascript/users/index.js
|
46
|
+
- test/simple_javascript_testing_test.rb
|
47
|
+
homepage: http://rubygems.org/gems/simple_javascript_testing
|
48
|
+
licenses:
|
49
|
+
- MIT
|
50
|
+
metadata: {}
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
requirements: []
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 2.2.2
|
68
|
+
signing_key:
|
69
|
+
specification_version: 4
|
70
|
+
summary: Simple Javascript Testing
|
71
|
+
test_files: []
|