qlive-rspec 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. data/.gitignore +9 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE +22 -0
  4. data/README.md +77 -0
  5. data/Rakefile +2 -0
  6. data/lib/qlive-rspec.rb +12 -0
  7. data/lib/qlive-rspec/version.rb +3 -0
  8. data/lib/qlive/matchers.rb +28 -0
  9. data/lib/qlive/rspec.rb +74 -0
  10. data/qlive-rspec.gemspec +24 -0
  11. data/spec/dummy/Gemfile +29 -0
  12. data/spec/dummy/README.md +19 -0
  13. data/spec/dummy/Rakefile +7 -0
  14. data/spec/dummy/app/assets/images/rails.png +0 -0
  15. data/spec/dummy/app/assets/javascripts/application.js +25 -0
  16. data/spec/dummy/app/assets/javascripts/backbone_on_rails_todo.js.coffee +11 -0
  17. data/spec/dummy/app/assets/javascripts/collections/todos.js.coffee +5 -0
  18. data/spec/dummy/app/assets/javascripts/models/todo.js.coffee +3 -0
  19. data/spec/dummy/app/assets/javascripts/routers/todo_app_router.js.coffee +14 -0
  20. data/spec/dummy/app/assets/javascripts/views/todo_app/todo_app.js.coffee +29 -0
  21. data/spec/dummy/app/assets/javascripts/views/todos/todo.js.coffee +12 -0
  22. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  23. data/spec/dummy/app/assets/stylesheets/todos.scss +45 -0
  24. data/spec/dummy/app/assets/templates/todo_list/index.jst.eco +11 -0
  25. data/spec/dummy/app/assets/templates/todos/index.jst.eco +1 -0
  26. data/spec/dummy/app/controllers/application_controller.rb +10 -0
  27. data/spec/dummy/app/controllers/todo_list_controller.rb +11 -0
  28. data/spec/dummy/app/controllers/todos_controller.rb +18 -0
  29. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  30. data/spec/dummy/app/helpers/todos_helper.rb +2 -0
  31. data/spec/dummy/app/mailers/.gitkeep +0 -0
  32. data/spec/dummy/app/models/todo.rb +12 -0
  33. data/spec/dummy/app/models/todo_list.rb +9 -0
  34. data/spec/dummy/app/views/layouts/application.html.erb +19 -0
  35. data/spec/dummy/app/views/todo_list/index.html.erb +11 -0
  36. data/spec/dummy/app/views/todos/create.html.erb +2 -0
  37. data/spec/dummy/app/views/todos/index.html.erb +2 -0
  38. data/spec/dummy/app/views/todos/new.html.erb +2 -0
  39. data/spec/dummy/config.ru +4 -0
  40. data/spec/dummy/config/application.rb +59 -0
  41. data/spec/dummy/config/boot.rb +6 -0
  42. data/spec/dummy/config/database.yml +20 -0
  43. data/spec/dummy/config/environment.rb +5 -0
  44. data/spec/dummy/config/environments/development.rb +37 -0
  45. data/spec/dummy/config/environments/production.rb +67 -0
  46. data/spec/dummy/config/environments/test.rb +37 -0
  47. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  48. data/spec/dummy/config/initializers/inflections.rb +15 -0
  49. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  50. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  51. data/spec/dummy/config/initializers/session_store.rb +8 -0
  52. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  53. data/spec/dummy/config/locales/en.yml +5 -0
  54. data/spec/dummy/config/routes.rb +15 -0
  55. data/spec/dummy/db/development.sqlite3 +0 -0
  56. data/spec/dummy/db/migrate/20120317122010_create_todos.rb +14 -0
  57. data/spec/dummy/db/schema.rb +29 -0
  58. data/spec/dummy/db/seeds.rb +7 -0
  59. data/spec/dummy/db/test.sqlite3 +0 -0
  60. data/spec/dummy/doc/README_FOR_APP +2 -0
  61. data/spec/dummy/lib/assets/.gitkeep +0 -0
  62. data/spec/dummy/lib/tasks/.gitkeep +0 -0
  63. data/spec/dummy/log/.gitkeep +0 -0
  64. data/spec/dummy/log/development.log +7086 -0
  65. data/spec/dummy/log/test.log +460 -0
  66. data/spec/dummy/public/404.html +26 -0
  67. data/spec/dummy/public/422.html +26 -0
  68. data/spec/dummy/public/500.html +25 -0
  69. data/spec/dummy/public/favicon.ico +0 -0
  70. data/spec/dummy/public/robots.txt +5 -0
  71. data/spec/dummy/script/rails +6 -0
  72. data/spec/dummy/script/test +1 -0
  73. data/spec/dummy/spec/factories/todo_lists.rb +7 -0
  74. data/spec/dummy/spec/factories/todos.rb +14 -0
  75. data/spec/dummy/spec/qunits/.DS_Store +0 -0
  76. data/spec/dummy/spec/qunits/adding_todos/adding_todos_qlive.rb +13 -0
  77. data/spec/dummy/spec/qunits/adding_todos/ajax-creation.js +18 -0
  78. data/spec/dummy/spec/qunits/qunit_support/qlive_helper.rb +0 -0
  79. data/spec/dummy/spec/qunits/qunit_support/qunit-starter.js +6 -0
  80. data/spec/dummy/spec/qunits/qunit_support/wait-for.js +24 -0
  81. data/spec/dummy/tmp/cache/assets/C5B/9C0/sprockets%2Faa69c6a6967552862782c17a264616f0 +0 -0
  82. data/spec/dummy/tmp/cache/assets/C85/B80/sprockets%2F98af874023c7cc2924ae87e605711532 +0 -0
  83. data/spec/dummy/tmp/cache/assets/C9A/C40/sprockets%2F729f761526e6c21ed96511f7277fe982 +0 -0
  84. data/spec/dummy/tmp/cache/assets/C9F/9A0/sprockets%2F1db451c19d955625f00aa51437df3152 +0 -0
  85. data/spec/dummy/tmp/cache/assets/CA5/800/sprockets%2F353700484461b1229e7cfb7b7c0ce640 +0 -0
  86. data/spec/dummy/tmp/cache/assets/CAB/1F0/sprockets%2F5bc32b49750b54325270c34377ede81e +0 -0
  87. data/spec/dummy/tmp/cache/assets/CAF/6B0/sprockets%2F2b7b92f831e2b43c590ca91b62708395 +0 -0
  88. data/spec/dummy/tmp/cache/assets/CBB/2E0/sprockets%2F9f57f2f115170a931f96bdb689312b94 +0 -0
  89. data/spec/dummy/tmp/cache/assets/CC1/EC0/sprockets%2Fe6256cd8969bf71b9e18729e631072a2 +0 -0
  90. data/spec/dummy/tmp/cache/assets/CD4/C30/sprockets%2Fd166012e1da02d12697c2ee0f574f690 +0 -0
  91. data/spec/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
  92. data/spec/dummy/tmp/cache/assets/CDC/F50/sprockets%2F614a5858458b9422d8e266fbaa6310ab +0 -0
  93. data/spec/dummy/tmp/cache/assets/CDF/CB0/sprockets%2Fd6f984ec9cf105b484172a66c00f0561 +0 -0
  94. data/spec/dummy/tmp/cache/assets/CFF/170/sprockets%2F4af4a5f916847c198f92a79e8f04287f +0 -0
  95. data/spec/dummy/tmp/cache/assets/D0D/830/sprockets%2F15213ba08baca38d909585e736bb9f44 +0 -0
  96. data/spec/dummy/tmp/cache/assets/D10/F10/sprockets%2F349a7d73940a1643fb3de693ca7cd244 +0 -0
  97. data/spec/dummy/tmp/cache/assets/D11/2F0/sprockets%2F36fc2e765d9cc09c50c0e55b1933a737 +0 -0
  98. data/spec/dummy/tmp/cache/assets/D26/620/sprockets%2F6926777d652a664ceb5aa28666efa7c9 +0 -0
  99. data/spec/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
  100. data/spec/dummy/tmp/cache/assets/D3E/F10/sprockets%2F75dd8ecd20427d22139517ae9f25ee2a +0 -0
  101. data/spec/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
  102. data/spec/dummy/tmp/cache/assets/D4E/F70/sprockets%2Fcf5cf57efa2c53a409b80285278e5f77 +0 -0
  103. data/spec/dummy/tmp/cache/assets/D52/090/sprockets%2F826a9bb15e4093dd94d248d9f90f9ed2 +0 -0
  104. data/spec/dummy/tmp/cache/assets/D53/7D0/sprockets%2F43c0246147f6192dfffbf8f68d793a6e +0 -0
  105. data/spec/dummy/tmp/cache/assets/D53/E30/sprockets%2Fffde997b0d35826e3175caa159968dc4 +0 -0
  106. data/spec/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
  107. data/spec/dummy/tmp/cache/assets/D5B/1B0/sprockets%2F36c7e9792a69fd67c686a16e382b5ffa +0 -0
  108. data/spec/dummy/tmp/cache/assets/D68/7D0/sprockets%2Fde9b9f45d0b5fa19cf672371102a1f0f +0 -0
  109. data/spec/dummy/tmp/cache/assets/D6F/C80/sprockets%2F69d138071bef8c9a34324bfdf2fd530d +0 -0
  110. data/spec/dummy/tmp/cache/assets/D71/020/sprockets%2Fe303c90d58293dcd7eb29d633c9cb54a +0 -0
  111. data/spec/dummy/tmp/cache/assets/D76/C40/sprockets%2F5dc3f2334568fee3c23c086463fefa8c +0 -0
  112. data/spec/dummy/tmp/cache/assets/D82/AD0/sprockets%2F042cc68bc2ce132b356c704abfaf107a +0 -0
  113. data/spec/dummy/tmp/cache/assets/D89/0B0/sprockets%2F7c8dc9875c0c22e89fdc595cdd9605f2 +0 -0
  114. data/spec/dummy/tmp/cache/assets/D8E/A00/sprockets%2Ff89d78b78be9a45cf7e944a57c82b26c +0 -0
  115. data/spec/dummy/tmp/cache/assets/D90/690/sprockets%2Fce78782d3fc61622015a80c2acc6cdba +0 -0
  116. data/spec/dummy/tmp/cache/assets/D99/330/sprockets%2Fe2a2a8724fee0fb701e358ee266cda62 +0 -0
  117. data/spec/dummy/tmp/cache/assets/D99/B80/sprockets%2Fc608b81fe3a10ffee85e0b63e9ca9201 +0 -0
  118. data/spec/dummy/tmp/cache/assets/DB0/B80/sprockets%2F96f6192adc54bf98a98d6fa190ebb74b +0 -0
  119. data/spec/dummy/tmp/cache/assets/DC6/AD0/sprockets%2Fcfcccca451e28002deb96721d94e25ce +0 -0
  120. data/spec/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
  121. data/spec/dummy/tmp/cache/assets/DE6/CE0/sprockets%2F6fda7e975c6df54bffda6598f431e5d1 +0 -0
  122. data/spec/dummy/tmp/cache/assets/DFD/350/sprockets%2Fdbea6b4a1f0b88258c29c6836bcca6ed +0 -0
  123. data/spec/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
  124. data/spec/dummy/tmp/cache/assets/E39/3B0/sprockets%2F9ae1c4c883d1dd6fc84cdbf1ff55d44f +0 -0
  125. data/spec/dummy/tmp/cache/sass/3a7aef2f892362e6596155ab72cedacbd9a1a7ed/todos.scssc +0 -0
  126. data/spec/dummy/tmp/cache/sass/3ac4a8f3985b4a79a98fc03388b5ded5e9bdc4aa/todos.scssc +0 -0
  127. data/spec/dummy/vendor/assets/javascripts/.gitkeep +0 -0
  128. data/spec/dummy/vendor/assets/stylesheets/.gitkeep +0 -0
  129. data/spec/dummy/vendor/plugins/.gitkeep +0 -0
  130. data/spec/qunits_spec.rb +7 -0
  131. data/spec/spec_helper.rb +14 -0
  132. metadata +365 -0
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ spec/dummy/db/*.sqlite3
5
+ spec/dummy/log/*.log
6
+ spec/dummy/tmp/
7
+ *.iml
8
+ *.gem
9
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in qlive-headless.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 TODO: Write your name
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,77 @@
1
+ # Qlive-Rspec
2
+
3
+ Run qlive-rails qunit javascript tests headlessly alongside your normal rspec integration examples.
4
+
5
+ This builds on the [qlive-rails](https://github.com/proxv/qlive-rails) gem. If you are using Ruby on Rails and rspec,
6
+ this gem will let you run your qlive tests in both a browser and headlessly as an rspec example/test.
7
+
8
+ Qlive-rspec has relatively heavy dependencies: virtual X11 frame buffer, headless webkit, capybara, and rspec.
9
+ If this doesn't work for you, it should be possible to incorporate your qlive tests into other automated testing
10
+ or continuous integration enviornments (eg, with a selenium-related library.)
11
+
12
+
13
+
14
+ ## Installation
15
+
16
+ * Install webkit-qt and xvfb on your system. Eg:
17
+ <pre>sudo aptitude install libqt4-dev xvfb</pre>
18
+
19
+ note: more detailed instructions at [capybara-webkit](https://github.com/thoughtbot/capybara-webkit) and [headless](https://github.com/leonid-shevtsov/headless) gems.
20
+
21
+
22
+ * Add qlive-rails and qlive-rspec to your Gemfile as follows:
23
+
24
+ ```ruby
25
+ group :test, :development do
26
+ gem 'qlive-rails', :require => 'qlive/engine'
27
+ end
28
+
29
+ group :test do
30
+ gem 'qlive-rspec'
31
+ end
32
+ ```
33
+
34
+ * As in qlive-rails, mount the engine in routes.rb:
35
+
36
+ ```ruby
37
+ if Rails.env == 'development'
38
+ mount Qlive::Engine => '/qlive'
39
+ end
40
+ ```
41
+
42
+
43
+
44
+
45
+ ## Usage
46
+
47
+ ### qunits_spec.rb
48
+
49
+ * After you have your [qlive suites](https://github.com/proxv/qlive/wiki/qlive-suites) working in a browser,
50
+ create ``spec/qunits/qunits_spec.rb``:
51
+
52
+ ```ruby
53
+ require "my_spec_helper.rb"
54
+
55
+ describe "qunits" do
56
+ include Qlive::RSpec
57
+ end
58
+ ```
59
+
60
+
61
+ * It will now run as a normal rspec example:
62
+ <pre>rspec spec/qunits</pre>
63
+
64
+
65
+ ### Configuration
66
+
67
+ * Optionally run setup/teardown code before and after the qlive tests are run.
68
+ <pre>
69
+ Qlive.setup[:before_suites] lambda { my_setup_code }
70
+ Qlive.setup[:after_suites] lambda { my_teardown_code }
71
+ </pre>
72
+
73
+ * Optionally set xvfb/headless gem to a custom configuration hash with: ``Qlive.setup[:headless_config] = my_settings_hash``
74
+
75
+ * Optionally disable xvfb with ``Qlive.setup[:start_xvfb] = false`` if you plan on configuring it externally
76
+
77
+ * Optionally change per-page timeout in seconds with: ``Qlive.setup[:capybara_wait_time] = 30``
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,12 @@
1
+ require "qlive-rspec/version"
2
+ require "qlive/rspec"
3
+
4
+
5
+ module QliveRSpec
6
+ Qlive.setup[:start_xvfb] = true unless Qlive.setup.has_key?(:start_xvfb)
7
+ Qlive.setup[:headless_config] = {
8
+ :display => 99
9
+ # :destroy_at_exit => true, :reuse => false
10
+ }
11
+ Qlive.setup[:capybara_wait_time] = 30
12
+ end
@@ -0,0 +1,3 @@
1
+ module QliveRSpec
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,28 @@
1
+ module Qlive
2
+ module Matchers
3
+ def self.add_matchers
4
+ ::RSpec::Matchers.define :pass_qunit_tests do |failure_text|
5
+ match do |page_actual|
6
+ url = page_actual.current_url
7
+ passed = page_actual.find('#qunit-testresult .passed').text.to_i rescue 0
8
+ failed = page_actual.find('#qunit-testresult .failed').text.to_i rescue 1
9
+ Qlive.logger.info "#{url } passed: #{passed}, failed: #{failed}"
10
+
11
+ failed == 0 && passed > 0
12
+ end
13
+
14
+ failure_message_for_should do |page_actual|
15
+ "qunit failure text: #{failure_text}"
16
+ end
17
+
18
+ failure_message_for_should_not do |page_actual|
19
+ "expected qunit test to fail but all passed."
20
+ end
21
+
22
+ description do
23
+ "pass qunit tests"
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,74 @@
1
+ require 'capybara/rspec'
2
+ require 'headless' # https://github.com/leonid-shevtsov/headless
3
+ require 'qlive/matchers'
4
+ require "#{Qlive::Engine.root}/app/helpers/qlive/suites_helper.rb"
5
+
6
+ module Qlive
7
+ module RSpec
8
+
9
+ describe "qlive" do
10
+ Qlive::Matchers.add_matchers
11
+
12
+ it "should define all qlive suites" do
13
+ # nested it/describe hackery explained: Rails.root path is needed before we can programmatically declare
14
+ # qunit examples, but it is not available until the examples start running. This hacky workaround nests the
15
+ # describe examples and example group that we want in another "it" declaration. todo: investigate better rspec integration
16
+
17
+ Qlive.setup[:base_path] ||= "#{Rails.root}/spec/qunits"
18
+ Qlive.setup[:logger] ||= Rails.logger
19
+ Qlive::Registry.find_suites
20
+
21
+ describe "pages", :type => :request do
22
+ extend Qlive::SuitesHelper
23
+
24
+ def visit_qunit_page(suite_name, href)
25
+ using_wait_time(Qlive.setup[:capybara_wait_time]) do # perhaps let suites override this value
26
+ Qlive.logger.info "Qlive sending capybara to run '#{suite_name}' on #{href}"
27
+ visit href
28
+ page.html.should_not be_nil
29
+ page.wait_until(Qlive.setup[:capybara_wait_time]) do # hmmmm
30
+ page.evaluate_script('!!window.qunitComplete')
31
+ end
32
+ failure_text = page.evaluate_script("$('li.fail li.fail').text();")
33
+ page.should pass_qunit_tests(failure_text)
34
+ end
35
+ end
36
+
37
+ Qlive::Registry.suites.values.each do |suite_meta|
38
+ load suite_meta[:path]
39
+ suite = Qlive::Registry.build_suite(suite_meta[:name])
40
+ hrefs_for_suite(suite).each do |href|
41
+ it "should pass qunit tests when visiting: #{href}" do
42
+ visit_qunit_page(suite.name, href)
43
+ end
44
+ end
45
+ end
46
+
47
+ before(:all) do
48
+ Qlive.setup[:before_suites].call if Qlive.setup[:before_suites]
49
+ if Qlive.setup[:start_xvfb]
50
+ @headless = ::Headless.new(Qlive.setup[:headless_config])
51
+ @headless.start
52
+ end
53
+ end
54
+
55
+ before(:each) do
56
+ page.reset!
57
+ end
58
+
59
+ after(:all) do
60
+ puts "\nGetting rough with headless webkit_server. In the event of a fatal IO error, use your judgement regarding calling the police."
61
+ @headless.destroy if @headless
62
+ if Qlive.setup[:after_suites]
63
+ Qlive.setup[:after_suites].call
64
+ end
65
+ end
66
+
67
+ end
68
+ end
69
+
70
+ end
71
+
72
+ end
73
+ end
74
+
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/qlive-rspec/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["ProxV"]
6
+ gem.email = ["support@proxv.com"]
7
+ gem.summary = "Run qlive-rails qunit javascript tests headlessly alongside your normal rspec integration examples"
8
+ gem.description = gem.summary
9
+ gem.homepage = "https://github.com/proxv/qlive-rspec/"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "qlive-rspec"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = QliveRSpec::VERSION
17
+
18
+ gem.add_dependency "qlive-rails", "~> 0.1.2"
19
+ gem.add_dependency "capybara-webkit", "0.10.0"
20
+ gem.add_dependency "rspec-rails", "~> 2.8.1"
21
+ gem.add_dependency "headless", "~> 0.3"
22
+ gem.add_development_dependency "rspec-rails", "~> 2.8.0"
23
+ gem.add_development_dependency "factory_girl_rails", "~> 3.5.0"
24
+ end
@@ -0,0 +1,29 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rails', '~> 3.2.3'
4
+ gem 'sqlite3'
5
+ gem 'haml-rails'
6
+
7
+ group :assets do
8
+ gem 'sass-rails', '~> 3.2.3'
9
+ gem 'coffee-rails', '~> 3.2.1'
10
+ gem 'uglifier', '>= 1.0.3'
11
+ end
12
+
13
+ gem 'jquery-rails'
14
+ gem 'backbone-on-rails'
15
+
16
+ group :development do
17
+ end
18
+
19
+ group :test, :development do
20
+ gem 'factory_girl_rails', '3.5.0'
21
+ gem 'qlive-rails', :require => 'qlive/engine' # https://github.com/proxv/qlive
22
+ end
23
+
24
+ group :test do
25
+ gem 'rspec-rails', '~> 2.8.1'
26
+ gem 'capybara-webkit', '0.10.0'
27
+ gem 'headless', '~> 0.2'
28
+ gem 'qlive-rspec', :path => File.expand_path('../../..', __FILE__)
29
+ end
@@ -0,0 +1,19 @@
1
+
2
+ # Dummy App
3
+
4
+ I randomly grabbed a demo app that uses rails and backbone:
5
+ https://github.com/mulderp/Backbone-on-Rails-todoDemo
6
+
7
+
8
+ ## Run dummy app qlive suites in browser
9
+ ```
10
+ cd qlive-rspec/spec/dummy
11
+ rails s
12
+ http://localhost/qlive
13
+ ```
14
+
15
+ ## Run dummy app qlive suites headlessly
16
+ ```
17
+ rspec spec/qunits
18
+ ```
19
+
@@ -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
+ BackboneOnRailsTodo::Application.load_tasks
@@ -0,0 +1,25 @@
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 underscore
16
+ //= require backbone
17
+
18
+ //= require backbone_on_rails_todo
19
+
20
+ //= require_tree ../templates
21
+ //= require_tree ./models
22
+ //= require_tree ./collections
23
+ //= require_tree ./views
24
+ //= require_tree ./routers
25
+ //= require_tree .
@@ -0,0 +1,11 @@
1
+ window.BackboneOnRailsTodo =
2
+ Models: {}
3
+ Collections: {}
4
+ Views: {}
5
+ Routers: {}
6
+ init: ->
7
+ new BackboneOnRailsTodo.Routers.TodoApp
8
+ Backbone.history.start()
9
+
10
+ $(document).ready ->
11
+ BackboneOnRailsTodo.init()
@@ -0,0 +1,5 @@
1
+ class BackboneOnRailsTodo.Collections.Todos extends Backbone.Collection
2
+ model: BackboneOnRailsTodo.Models.Todo
3
+ url: '/todos'
4
+
5
+
@@ -0,0 +1,3 @@
1
+ class BackboneOnRailsTodo.Models.Todo extends Backbone.Model
2
+
3
+
@@ -0,0 +1,14 @@
1
+ class BackboneOnRailsTodo.Routers.TodoApp extends Backbone.Router
2
+ routes:
3
+ '': 'index'
4
+ 'colors/:color': 'index'
5
+
6
+ initialize: ->
7
+ @todos = new BackboneOnRailsTodo.Collections.Todos()
8
+ @todos.fetch()
9
+
10
+ index: (color) ->
11
+ view = new BackboneOnRailsTodo.Views.TodoApp({collection: @todos})
12
+ $('#todo-list').html(view.render().el)
13
+ $('<style>#todo-list li { color: ' + (color || 'green') + ';}</style>').appendTo('body')
14
+
@@ -0,0 +1,29 @@
1
+ class BackboneOnRailsTodo.Views.TodoApp extends Backbone.View
2
+
3
+ el: $('#todoapp')
4
+
5
+ initialize: ->
6
+ @collection.on('reset', @addAll, this)
7
+ @collection.on('add', this.addOne, this)
8
+ $('#new-todo').on "keypress", {collection: @collection}, @keyTodoInput
9
+
10
+ addAll: ->
11
+ @collection.each(@addOne)
12
+
13
+ addOne: (todo) ->
14
+ console.log(todo)
15
+ view = new BackboneOnRailsTodo.Views.Todo({model: todo})
16
+ $("#todo-list").append(view.render().el)
17
+
18
+ createTodo: (event) ->
19
+ event.preventDefault()
20
+ BackboneOnRailsTodo.Collections.Todos.create content: $('#new-todo-content').val()
21
+
22
+ keyTodoInput: (e) ->
23
+ # console.log(event.type, event.keyCode)
24
+ return if (e.keyCode != 13)
25
+ return if (!this.value)
26
+ console.log(e.data.collection)
27
+
28
+ e.data.collection.create content: this.value
29
+ this.value = ''
@@ -0,0 +1,12 @@
1
+ class BackboneOnRailsTodo.Views.Todo extends Backbone.View
2
+
3
+ tagName: 'li'
4
+
5
+ template: JST['todos/index']
6
+
7
+ initialize: (todo) ->
8
+ @todo = todo.model
9
+
10
+ render: ->
11
+ $(@el).html(@template(todo: @todo))
12
+ this