qlive-rails 0.1.0
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.
- data/README.md +57 -0
- data/Rakefile +39 -0
- data/app/assets/javascripts/qlive/suites.js +3 -0
- data/app/assets/stylesheets/qlive/suites.css +13 -0
- data/app/controllers/qlive/sources_controller.rb +14 -0
- data/app/controllers/qlive/suites_controller.rb +14 -0
- data/app/helpers/qlive/suites_helper.rb +45 -0
- data/app/views/layouts/qlive/suites.html.haml +11 -0
- data/app/views/qlive/suites/index.html.haml +27 -0
- data/config/routes.rb +4 -0
- data/lib/qlive/engine.rb +27 -0
- data/lib/qlive/version.rb +3 -0
- data/lib/qlive.rb +7 -0
- data/lib/tasks/qlive_tasks.rake +4 -0
- metadata +94 -0
data/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# Qlive-Rails
|
2
|
+
|
3
|
+
Qlive-Rails is a Ruby on Rails engine for running qunit javascript tests using server-side factories and user login.
|
4
|
+
|
5
|
+
|
6
|
+
Using the [qlive](https://github.com/proxv/qlive) gem, it provides hooks for setting server state
|
7
|
+
before the request is processed by your app, so you can do things like popuplate the page's content with
|
8
|
+
your favorite fixtures library (like factory_girl) and log in a user.
|
9
|
+
Qlive inserts the qunit framework and all of your test sources into the page's response.
|
10
|
+
|
11
|
+
It is mainly intended to be used for testing javascript-heavy, single-page web applications
|
12
|
+
(like those built using backbone, angularjs, emberjs, etc.)
|
13
|
+
|
14
|
+
|
15
|
+
## Benefits:
|
16
|
+
|
17
|
+
* Precisely set fixture content and user login state for your qunit tests
|
18
|
+
* Run the same tests in a browser or headlessly, alongside your normal integration test suite. (with the [qlive-headless](https://github.com/proxv/qlive-headless) gem)
|
19
|
+
* A dashboard page to link to all of your qlive test suites
|
20
|
+
|
21
|
+
|
22
|
+
## Installation
|
23
|
+
|
24
|
+
To run qlive headlessly as well as in the browser, use [qlive-headless](https://github.com/proxv/qlive-headless).
|
25
|
+
|
26
|
+
For browser-only testing against Ruby on Rails 3, do the following:
|
27
|
+
|
28
|
+
* Add qlive-rails to your Gemfile:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
group :development do
|
32
|
+
gem 'qlive-rails', :require => 'qlive/engine'
|
33
|
+
end
|
34
|
+
```
|
35
|
+
|
36
|
+
|
37
|
+
* Mount the engine in routes.rb:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
if Rails.env == 'development'
|
41
|
+
mount Qlive::Engine => '/qlive'
|
42
|
+
end
|
43
|
+
```
|
44
|
+
|
45
|
+
|
46
|
+
## Usage
|
47
|
+
|
48
|
+
|
49
|
+
Wiki pages:
|
50
|
+
|
51
|
+
* [Qlive-suites](https://github.com/proxv/qlive/wiki/qlive-suites) for how to use qlive and create suites.
|
52
|
+
|
53
|
+
* [Factory_girl Tips](https://github.com/proxv/qlive/wiki/factory-girl-tips) for how to use factory girl in your qlive suites.
|
54
|
+
|
55
|
+
* [Devise Tips](https://github.com/proxv/qlive/wiki/devise-tips) for logging in users with devise in your qlive suites.
|
56
|
+
|
57
|
+
* Once you have some qlive suites in place, visit /qlive in your app and follow the links within to run them.
|
data/Rakefile
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'Qlive'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
|
24
|
+
load 'rails/tasks/engine.rake'
|
25
|
+
|
26
|
+
|
27
|
+
Bundler::GemHelper.install_tasks
|
28
|
+
|
29
|
+
require 'rake/testtask'
|
30
|
+
|
31
|
+
Rake::TestTask.new(:test) do |t|
|
32
|
+
t.libs << 'lib'
|
33
|
+
t.libs << 'test'
|
34
|
+
t.pattern = 'test/**/*_test.rb'
|
35
|
+
t.verbose = false
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
task :default => :test
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Qlive
|
2
|
+
class SourcesController < ActionController::Base
|
3
|
+
|
4
|
+
def show
|
5
|
+
base_path = Qlive.setup[:base_path]
|
6
|
+
rel_path = params[:rel_path]
|
7
|
+
path = File.expand_path("./#{rel_path}#{rel_path.end_with?('.js') ? '' : '.js'}", base_path)
|
8
|
+
raise "Illegal path: #{path}" unless path.start_with?(base_path)
|
9
|
+
headers['Content-Type'] = 'application/javascript' # serve other types? If so: (Mime::Type.lookup_by_extension(params[:format]).to_s rescue 'text/text')
|
10
|
+
render :text => IO.read(path), :status => 200
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Qlive
|
2
|
+
class SuitesController < ActionController::Base
|
3
|
+
|
4
|
+
def index
|
5
|
+
Qlive::DevReload.reload_main if Qlive.setup[:gem_dev_mode]
|
6
|
+
Qlive::Registry.find_suites
|
7
|
+
@suites = Qlive::Registry.suites.keys.map do |suite_name|
|
8
|
+
Qlive::Registry.build_suite(suite_name)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Qlive
|
2
|
+
module SuitesHelper
|
3
|
+
|
4
|
+
def hrefs_for_suite(suite)
|
5
|
+
return [] unless suite.respond_to?(:pages_to_test)
|
6
|
+
href_array(suite, suite.pages_to_test)
|
7
|
+
end
|
8
|
+
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def href_array(suite, val)
|
13
|
+
if val.nil?
|
14
|
+
[ ]
|
15
|
+
elsif val.kind_of?(String)
|
16
|
+
[ append_suite_command(suite, val) ]
|
17
|
+
elsif val.kind_of?(Array)
|
18
|
+
val.map { |v| append_suite_command(suite, v)}
|
19
|
+
else
|
20
|
+
href_array(suite, val.call)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
def append_suite_command(suite, href)
|
26
|
+
param = "qlive=#{suite.name}"
|
27
|
+
# todo: use url/uri library to make this cleaner
|
28
|
+
pos = href.index('?')
|
29
|
+
if pos
|
30
|
+
res = "#{href[0, pos + 1]}#{param}&#{href[(pos + 1)..-1]}"
|
31
|
+
else
|
32
|
+
pos = href.index('#')
|
33
|
+
if pos
|
34
|
+
res = "#{href[0, pos]}?#{param}#{href[pos..-1]}"
|
35
|
+
else
|
36
|
+
res = "#{href}?#{param}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
res
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
!!! 5
|
2
|
+
%html{ :xmlns => "http://www.w3.org/1999/xhtml", :lang => "en", "xml:lang" => "en" }
|
3
|
+
%head
|
4
|
+
%meta{ :charset => "utf-8" }
|
5
|
+
%meta{ "http-equiv" => "X-UA-Compatible", :content => "IE=edge,chrome=1" }
|
6
|
+
= stylesheet_link_tag "/qlive/qunit-1.9.0/qunit.css", :media => 'all'
|
7
|
+
= stylesheet_link_tag "qlive/suites", :media => 'all'
|
8
|
+
%title= 'Qlive Suites'
|
9
|
+
|
10
|
+
%body
|
11
|
+
= yield
|
@@ -0,0 +1,27 @@
|
|
1
|
+
%h1#qunit-header
|
2
|
+
%strong Qlive-Rails
|
3
|
+
%h2.qunit-pass#qunit-banner
|
4
|
+
-# leave banner empty (its a thin green strip, dunno why they used an h2)
|
5
|
+
#qunit-testrunner-toolbar
|
6
|
+
= "Found #{pluralize(@suites.length, 'qlive suite')} in #{Qlive.setup[:base_path].sub(Rails.root.to_s + '/', '')} directory tree."
|
7
|
+
%h2#qunit-userAgent
|
8
|
+
Pages registered to run qunit qlive suites:
|
9
|
+
|
10
|
+
%ol#qunit-tests
|
11
|
+
- if @suites.length > 0
|
12
|
+
- @suites.each do |suite|
|
13
|
+
- hrefs = hrefs_for_suite(suite)
|
14
|
+
- has_links = hrefs.length > 0
|
15
|
+
%li{ :class => has_links ? 'pass' : 'fail' }
|
16
|
+
%strong.module-name= "Suite '#{suite.name}' has #{pluralize(hrefs.length, 'test page')}."
|
17
|
+
%ol
|
18
|
+
- if has_links
|
19
|
+
- hrefs.each do |href|
|
20
|
+
%li.pass
|
21
|
+
%a.test-message.test-page-link{ :href => href}= href
|
22
|
+
- else
|
23
|
+
%li
|
24
|
+
.test-message This suite is not declaring any links to pages in your app. <i>Set them with suite#pages_to_test()</i>
|
25
|
+
- else
|
26
|
+
%li.fail
|
27
|
+
%strong No Qlive Suites Found
|
data/config/routes.rb
ADDED
data/lib/qlive/engine.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'qlive/rack'
|
2
|
+
require 'qlive/dev_reload'
|
3
|
+
require 'qlive/suite'
|
4
|
+
|
5
|
+
module Qlive
|
6
|
+
class Engine < Rails::Engine
|
7
|
+
|
8
|
+
initializer "qlive" do |app|
|
9
|
+
Qlive.setup[:base_path] ||= "#{Rails.root}/spec/qunits"
|
10
|
+
|
11
|
+
puts "Mounting Qlive::Rack to allow qunit testing against your server's backend. (Never use this rack on production systems.)"
|
12
|
+
if Qlive.setup[:hand_mounted]
|
13
|
+
Qlive.setup[:hand_mounted].call
|
14
|
+
else
|
15
|
+
app.middleware.insert_after(::ActionDispatch::ParamsParser, Qlive::Rack, {
|
16
|
+
:base_path => Qlive.setup[:base_path]
|
17
|
+
})
|
18
|
+
app.middleware.insert_after ::ActionDispatch::Static, ::ActionDispatch::Static, "#{root}/public"
|
19
|
+
end
|
20
|
+
|
21
|
+
if Qlive.setup[:gem_dev_mode]
|
22
|
+
app.middleware.insert_before(::ActionDispatch::ParamsParser, Qlive::DevReload)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
data/lib/qlive.rb
ADDED
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: qlive-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- ProxV
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-07-26 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: qlive
|
16
|
+
requirement: &2152342160 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0.1'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2152342160
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rails
|
27
|
+
requirement: &2152340180 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '3.2'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2152340180
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rspec-rails
|
38
|
+
requirement: &2152337900 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 2.8.0
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *2152337900
|
47
|
+
description: Ruby on Rails engine for running qunit javascript tests using server-side
|
48
|
+
factories and user login
|
49
|
+
email:
|
50
|
+
- support@proxv.com
|
51
|
+
executables: []
|
52
|
+
extensions: []
|
53
|
+
extra_rdoc_files: []
|
54
|
+
files:
|
55
|
+
- app/assets/javascripts/qlive/suites.js
|
56
|
+
- app/assets/stylesheets/qlive/suites.css
|
57
|
+
- app/controllers/qlive/sources_controller.rb
|
58
|
+
- app/controllers/qlive/suites_controller.rb
|
59
|
+
- app/helpers/qlive/suites_helper.rb
|
60
|
+
- app/views/layouts/qlive/suites.html.haml
|
61
|
+
- app/views/qlive/suites/index.html.haml
|
62
|
+
- config/routes.rb
|
63
|
+
- lib/qlive/engine.rb
|
64
|
+
- lib/qlive/version.rb
|
65
|
+
- lib/qlive.rb
|
66
|
+
- lib/tasks/qlive_tasks.rake
|
67
|
+
- Rakefile
|
68
|
+
- README.md
|
69
|
+
homepage: https://github.com/proxv/qlive-rails/
|
70
|
+
licenses: []
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ! '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ! '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
requirements: []
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 1.8.10
|
90
|
+
signing_key:
|
91
|
+
specification_version: 3
|
92
|
+
summary: Ruby on Rails engine for running qunit javascript tests using server-side
|
93
|
+
factories and user login
|
94
|
+
test_files: []
|