transactional_capybara 0.1.0.pre.2 → 0.1.0.pre.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1734358fb0654defcb9c353940bf2e34ab7da006
4
+ data.tar.gz: caa82834cde32a345c9fd643b037d30e26d333f9
5
+ SHA512:
6
+ metadata.gz: 20c099399240513932b8814c8d5f18a40c77c59066768329014e4bef6592daeed2381c8f38a14832e109df98588b490017d372748d605b7890ced743578f02cf
7
+ data.tar.gz: 6a21b2f64c446f345ba7d2ecc5a43ed2ca1232c373c5a35ab45cc078e9e988af29a5637a28353c6a360a0560924d77cd32e7d32523468b39ccaccf573ba11fa1
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ spec/config.yml
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.2.2
data/.travis.yml ADDED
@@ -0,0 +1,15 @@
1
+ language: ruby
2
+ rvm:
3
+ - "1.9.3"
4
+ - "2.0"
5
+ - "2.1"
6
+ - "2.2"
7
+ before_install:
8
+ - "/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -ac -screen 0 1280x1024x16"
9
+ - "export DISPLAY=:99.0"
10
+ before_script:
11
+ - mysql -e "create database IF NOT EXISTS transactional_capybara_test;" -uroot
12
+ - psql -c 'create database transactional_capybara_test;' -U postgres
13
+ - "cp spec/{.travis.,}config.yml"
14
+ script: bundle exec rake test:all
15
+ sudo: false
data/README.md CHANGED
@@ -110,3 +110,12 @@ I'd love a pull request, or even just a friendly inquiry!
110
110
  4. Push to the branch (`git push origin my-new-feature`)
111
111
  5. Think about how I'm a bad person for not writing any tests yet
112
112
  6. Create new Pull Request
113
+
114
+ ### Running the tests ###
115
+
116
+ ```
117
+ cp spec/support/config.yml{.example,} # Edit as necessary
118
+ DB=sqlite rspec spec
119
+ ```
120
+
121
+ You can run the specs with other databases as well, but you will have to create the databases and users manually first.
data/Rakefile CHANGED
@@ -1 +1,22 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+ require 'yaml'
4
+ require 'active_support'
5
+
6
+ namespace :test do
7
+ RSpec::Core::RakeTask.new(:rspec)
8
+
9
+ desc "Run tests against all drivers and all databases listed in the config"
10
+ task :all do
11
+ db_config = YAML.load_file(File.join(File.dirname(__FILE__), "spec/config.yml"))
12
+ db_config["database"].keys.each do |db_name|
13
+ ENV['DB'] = db_name
14
+ %w[selenium webkit].each do |driver|
15
+ ENV['DRIVER'] = driver
16
+ puts ENV.to_hash.slice 'DRIVER', 'DB'
17
+ Rake::Task['test:rspec'].reenable
18
+ Rake::Task['test:rspec'].invoke
19
+ end
20
+ end
21
+ end
22
+ end
@@ -26,12 +26,15 @@ module TransactionalCapybara
26
26
  ).zero?
27
27
  end
28
28
 
29
+ # TODO: timeout each individual session
29
30
  def wait_until(timeout=Capybara.default_wait_time)
30
31
  Timeout.timeout(timeout) do
31
32
  until yield
32
33
  sleep(0.01)
33
34
  end
34
35
  end
36
+ rescue Timeout::Error
37
+ # Oh well, hopefully it finished!
35
38
  end
36
39
 
37
40
  private
@@ -47,7 +50,7 @@ module TransactionalCapybara
47
50
  end
48
51
 
49
52
  def run_js(expr)
50
- @page.execute_script(expr)
53
+ @page.evaluate_script(expr)
51
54
  end
52
55
 
53
56
  def angular?
@@ -1,3 +1,5 @@
1
+ require 'transactional_capybara'
2
+
1
3
  RSpec.configure do |config|
2
4
  TransactionalCapybara.share_connection
3
5
  config.after(:each, js: true) do
@@ -1,3 +1,3 @@
1
1
  module TransactionalCapybara
2
- VERSION = "0.1.0.pre.2"
2
+ VERSION = "0.1.0.pre.3"
3
3
  end
@@ -0,0 +1,14 @@
1
+ ---
2
+ database:
3
+ mysql:
4
+ adapter: mysql2
5
+ host: localhost
6
+ username: travis
7
+ database: transactional_capybara_test
8
+ sqlite:
9
+ adapter: sqlite3
10
+ database: ":memory:"
11
+ postgres:
12
+ adapter: postgresql
13
+ username: postgres
14
+ database: transactional_capybara_test
data/spec/ajax_spec.rb ADDED
@@ -0,0 +1,74 @@
1
+ require_relative 'support/server'
2
+ require_relative 'support/model'
3
+
4
+ RSpec.describe "server with AJAX", type: :feature, js: true do
5
+ before do
6
+ Capybara.app = AjaxServer
7
+ AjaxServer.should_return_from_ajax = false
8
+ @expected_message = "foobar"
9
+ TestValue.create! content: @expected_message
10
+ end
11
+
12
+ it "waits for AJAX" do
13
+ visit "/page_with_ajax"
14
+ expect(page).to have_content("Hello")
15
+ Thread.fork do
16
+ sleep 0.5
17
+ AjaxServer.should_return_from_ajax = true
18
+ end
19
+ expect(find(".message").text).not_to eq(@expected_message)
20
+ TransactionalCapybara::AjaxHelpers.wait_for_ajax(page)
21
+ expect(find(".message").text).to eq(@expected_message)
22
+ end
23
+
24
+ context "after hook", check_result_after: true do
25
+ it "automatically waits for AJAX" do
26
+ visit "/page_with_ajax"
27
+ expect(page).to have_content("Hello")
28
+ Thread.fork do
29
+ sleep 0.5
30
+ AjaxServer.should_return_from_ajax = true
31
+ end
32
+ expect(find(".message").text).not_to eq(@expected_message)
33
+ end
34
+ end
35
+
36
+ it "waits on all sessions" do
37
+ using_session :foo do
38
+ visit "/page_with_ajax"
39
+ expect(page).to have_content("Hello")
40
+ end
41
+
42
+ using_session :bar do
43
+ visit "/boring_page"
44
+ expect(page).to have_content("Hi")
45
+ end
46
+
47
+ Thread.fork do
48
+ sleep 0.5
49
+ AjaxServer.should_return_from_ajax = true
50
+ end
51
+ TransactionalCapybara::AjaxHelpers.wait_for_ajax(page)
52
+
53
+ using_session :foo do
54
+ expect(find(".message").text).to eq(@expected_message)
55
+ end
56
+
57
+ AjaxServer.should_return_from_ajax = false
58
+
59
+ using_session :bar do
60
+ visit "/page_with_ajax"
61
+ expect(page).to have_content("Hello")
62
+ end
63
+
64
+ Thread.fork do
65
+ sleep 0.5
66
+ AjaxServer.should_return_from_ajax = true
67
+ end
68
+ TransactionalCapybara::AjaxHelpers.wait_for_ajax(page)
69
+
70
+ using_session :bar do
71
+ expect(find(".message").text).to eq(@expected_message)
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,18 @@
1
+ ---
2
+ database:
3
+ mysql:
4
+ adapter: mysql2
5
+ host: localhost
6
+ username: transactional_capybara
7
+ password: abcd1234
8
+ database: transactional_capybara
9
+ sqlite:
10
+ adapter: sqlite3
11
+ host: localhost
12
+ database: tmp/test.db
13
+ postgres:
14
+ adapter: postgresql
15
+ host: localhost
16
+ username: transactional_capybara
17
+ password: abcd1234
18
+ database: transactional_capybara
@@ -0,0 +1,26 @@
1
+ require 'yaml'
2
+ db_type = ENV['DB'] || 'sqlite'
3
+ db_config = YAML.load_file(File.join(File.dirname(__FILE__), "config.yml"))
4
+ db = db_config["database"][db_type]
5
+
6
+ require 'active_record'
7
+ ActiveRecord::Base.establish_connection(db)
8
+ load File.join(File.dirname(__FILE__), "support/schema.rb")
9
+
10
+ require 'capybara/rspec'
11
+ require 'capybara-webkit'
12
+
13
+ capybara_driver = ENV['DRIVER'] || 'selenium'
14
+ Capybara.javascript_driver = capybara_driver.to_sym
15
+
16
+ RSpec.configure do |config|
17
+ config.expect_with :rspec do |expectations|
18
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
19
+ end
20
+
21
+ config.after(:each, check_result_after: true) do
22
+ expect(find(".message").text).to eq(@expected_message)
23
+ end
24
+ end
25
+
26
+ require 'transactional_capybara/rspec'
@@ -0,0 +1,3 @@
1
+ ActiveRecord::Migration.create_table :test_values do |t|
2
+ t.string :content
3
+ end
@@ -0,0 +1,2 @@
1
+ class TestValue < ActiveRecord::Base
2
+ end
@@ -0,0 +1,5 @@
1
+ ActiveRecord::Schema.define do
2
+ create_table :test_values, :force => true do |t|
3
+ t.string :content
4
+ end
5
+ end
@@ -0,0 +1,22 @@
1
+ require 'sinatra'
2
+ require 'tilt/erb'
3
+ require_relative 'model'
4
+
5
+ class AjaxServer < Sinatra::Base
6
+ cattr_accessor :should_return_from_ajax
7
+
8
+ get "/boring_page" do
9
+ erb "Hi", layout: :basic
10
+ end
11
+
12
+ get "/page_with_ajax" do
13
+ erb :page_with_ajax, layout: :basic
14
+ end
15
+
16
+ get "/ajax_endpoint" do
17
+ until AjaxServer.should_return_from_ajax do
18
+ sleep 0.01
19
+ end
20
+ TestValue.last.content
21
+ end
22
+ end
@@ -0,0 +1,11 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
6
+ <title></title>
7
+ </head>
8
+ <body>
9
+ <%= yield %>
10
+ </body>
11
+ </html>
@@ -0,0 +1,14 @@
1
+ <p class="message">Nothing to see</p>
2
+
3
+ <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.js"></script>
4
+ <script>window.jQuery || document.write('<script src="js/vendor/jquery-1.11.2.js"><\/script>')</script>
5
+ <script>
6
+ jQuery(function() {
7
+ jQuery.ajax('/ajax_endpoint', {
8
+ success: function(data) {
9
+ jQuery(".message").text(data);
10
+ }
11
+ });
12
+ jQuery(".message").text("Hello!");
13
+ });
14
+ </script>
@@ -18,6 +18,16 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
+ spec.add_dependency "capybara"
22
+
21
23
  spec.add_development_dependency "bundler", "~> 1.3"
22
24
  spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "sinatra"
26
+ spec.add_development_dependency "rspec"
27
+ spec.add_development_dependency "activerecord"
28
+ spec.add_development_dependency "mysql2"
29
+ spec.add_development_dependency "sqlite3"
30
+ spec.add_development_dependency "pg"
31
+ spec.add_development_dependency "selenium-webdriver"
32
+ spec.add_development_dependency "capybara-webkit"
23
33
  end
metadata CHANGED
@@ -1,46 +1,167 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: transactional_capybara
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.pre.2
5
- prerelease: 6
4
+ version: 0.1.0.pre.3
6
5
  platform: ruby
7
6
  authors:
8
7
  - Ian Young
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2015-08-25 00:00:00.000000000 Z
11
+ date: 2015-08-27 00:00:00.000000000 Z
13
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: capybara
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
14
27
  - !ruby/object:Gem::Dependency
15
28
  name: bundler
16
29
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
30
  requirements:
19
- - - ~>
31
+ - - "~>"
20
32
  - !ruby/object:Gem::Version
21
33
  version: '1.3'
22
34
  type: :development
23
35
  prerelease: false
24
36
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
37
  requirements:
27
- - - ~>
38
+ - - "~>"
28
39
  - !ruby/object:Gem::Version
29
40
  version: '1.3'
30
41
  - !ruby/object:Gem::Dependency
31
42
  name: rake
32
43
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
44
  requirements:
35
- - - ! '>='
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sinatra
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: activerecord
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: mysql2
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: sqlite3
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: pg
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: selenium-webdriver
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: capybara-webkit
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
36
158
  - !ruby/object:Gem::Version
37
159
  version: '0'
38
160
  type: :development
39
161
  prerelease: false
40
162
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
163
  requirements:
43
- - - ! '>='
164
+ - - ">="
44
165
  - !ruby/object:Gem::Version
45
166
  version: '0'
46
167
  description: Support for DB transactions with Capybara
@@ -50,7 +171,10 @@ executables: []
50
171
  extensions: []
51
172
  extra_rdoc_files: []
52
173
  files:
53
- - .gitignore
174
+ - ".gitignore"
175
+ - ".rspec"
176
+ - ".ruby-version"
177
+ - ".travis.yml"
54
178
  - Gemfile
55
179
  - LICENSE.txt
56
180
  - README.md
@@ -60,33 +184,51 @@ files:
60
184
  - lib/transactional_capybara/rspec.rb
61
185
  - lib/transactional_capybara/shared_connection.rb
62
186
  - lib/transactional_capybara/version.rb
187
+ - spec/.travis.config.yml
188
+ - spec/ajax_spec.rb
189
+ - spec/config.yml.example
190
+ - spec/spec_helper.rb
191
+ - spec/support/migration.rb
192
+ - spec/support/model.rb
193
+ - spec/support/schema.rb
194
+ - spec/support/server.rb
195
+ - spec/support/views/basic.erb
196
+ - spec/support/views/page_with_ajax.erb
63
197
  - transactional_capybara.gemspec
64
198
  homepage: ''
65
199
  licenses:
66
200
  - MIT
201
+ metadata: {}
67
202
  post_install_message:
68
203
  rdoc_options: []
69
204
  require_paths:
70
205
  - lib
71
206
  required_ruby_version: !ruby/object:Gem::Requirement
72
- none: false
73
207
  requirements:
74
- - - ! '>='
208
+ - - ">="
75
209
  - !ruby/object:Gem::Version
76
210
  version: '0'
77
211
  required_rubygems_version: !ruby/object:Gem::Requirement
78
- none: false
79
212
  requirements:
80
- - - ! '>'
213
+ - - ">"
81
214
  - !ruby/object:Gem::Version
82
215
  version: 1.3.1
83
216
  requirements: []
84
217
  rubyforge_project:
85
- rubygems_version: 1.8.23
218
+ rubygems_version: 2.4.5
86
219
  signing_key:
87
- specification_version: 3
220
+ specification_version: 4
88
221
  summary: Speed up your test suite with database transactions, without losing your
89
222
  mind to Capybara connection problems. Supports shared connections, plus AJAX watchers
90
223
  to avoid common deadlock scenarios.
91
- test_files: []
92
- has_rdoc:
224
+ test_files:
225
+ - spec/.travis.config.yml
226
+ - spec/ajax_spec.rb
227
+ - spec/config.yml.example
228
+ - spec/spec_helper.rb
229
+ - spec/support/migration.rb
230
+ - spec/support/model.rb
231
+ - spec/support/schema.rb
232
+ - spec/support/server.rb
233
+ - spec/support/views/basic.erb
234
+ - spec/support/views/page_with_ajax.erb