ghost_pictures 0.2.0

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: e8d0ceb13a2bce8e0cdb0a360f8c60f650535275
4
+ data.tar.gz: 8eb2ef6ee14e5d80f8c161760089ba904d3cab92
5
+ SHA512:
6
+ metadata.gz: 9d793096c0223e6dbaa3ad94d772c278fae841af9b5ac55fa19f832ca2ff13c7df2c617c39ecafddb3cf9a8a49ebaebfcf1302c2cc08c31bf5e068ee9fd809f8
7
+ data.tar.gz: a2799ad1d6921fa5d561949833e5e6c9e542b165ef5cc95ccad5bc4bfa972f9821c481df81cab4cd3b68df4fb939b2c2ffc3ca91e99ed6e6fced07817b3b067a
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,14 @@
1
+ AllCops:
2
+ DisplayCopNames: true
3
+ DisplayStyleGuide: true
4
+ ExtraDetails: true
5
+ TargetRubyVersion: 2.3
6
+
7
+ Metrics/LineLength:
8
+ Enabled: false
9
+
10
+ Metrics/BlockLength:
11
+ Enabled: false
12
+
13
+ Style/Documentation:
14
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,16 @@
1
+ sudo: required
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.2
5
+ - ruby-head
6
+ addons:
7
+ chrome: stable
8
+ before_install:
9
+ - gem install bundler -v 1.15.4
10
+ - wget https://chromedriver.storage.googleapis.com/2.33/chromedriver_linux64.zip
11
+ - unzip -d ~/ chromedriver_linux64.zip
12
+ - sudo mv -f ~/chromedriver /usr/local/share/
13
+ - sudo chmod +x /usr/local/share/chromedriver
14
+ - sudo ln -s /usr/local/share/chromedriver /usr/local/bin/chromedriver
15
+ notifications:
16
+ email: false
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in ghost_pictures.gemspec
8
+ gemspec
data/README.md ADDED
@@ -0,0 +1,64 @@
1
+ # GhostPictures
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/ghost_pictures.svg)](https://badge.fury.io/rb/ghost_pictures)
4
+ [![Build Status](https://travis-ci.org/sinsoku/ghost_pictures.svg?branch=master)](https://travis-ci.org/sinsoku/ghost_pictures)
5
+
6
+ GhostPictures provides the feature to wait for Ajax requests with [Capybara](https://github.com/teamcapybara/capybara).
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'ghost_pictures', group: :test
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install ghost_pictures
23
+
24
+ ## Setup
25
+
26
+ ### Rails
27
+
28
+ ```rb
29
+ # config/environments/test.rb
30
+ config.middleware.use GhostPictures::Capture
31
+ ```
32
+
33
+ ## Examples
34
+
35
+ ### Wait for a Ajax request
36
+
37
+ ```rb
38
+ GhostPictures.wait_for { click_link "get data via Ajax" }
39
+ ```
40
+
41
+ ### Wait for matching requests
42
+
43
+ ```rb
44
+ # Wait for a request with "/users"
45
+ GhostPictures.wait_for("/users") { click_link }
46
+
47
+ # Wait for a POST request with "/users"
48
+ GhostPictures.wait_for("/users", method: :post) { click_link }
49
+
50
+ # Wait for two requests
51
+ GhostPictures.wait_for(nil, count: 2) do
52
+ 2.times { click_link }
53
+ end
54
+ ```
55
+
56
+ ## Development
57
+
58
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
59
+
60
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
61
+
62
+ ## Contributing
63
+
64
+ Bug reports and pull requests are welcome on GitHub at https://github.com/sinsoku/ghost_pictures.
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require 'rubocop/rake_task'
9
+ RuboCop::RakeTask.new
10
+
11
+ task default: %i[rubocop spec]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'ghost_pictures'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,31 @@
1
+
2
+ # frozen_string_literal: true
3
+
4
+ lib = File.expand_path('../lib', __FILE__)
5
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
+ require 'ghost_pictures/version'
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = 'ghost_pictures'
10
+ spec.version = GhostPictures::VERSION
11
+ spec.authors = ['sinsoku']
12
+ spec.email = ['sinsoku.listy@gmail.com']
13
+
14
+ spec.summary = 'GhostPictures provides the feature to wait for Ajax requests with Capybara.'
15
+ spec.description = 'GhostPictures provides the feature to wait for Ajax requests with Capybara.'
16
+ spec.homepage = 'https://github.com/sinsoku/ghost_pictures'
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
19
+ f.match(%r{^(test|spec|features)/})
20
+ end
21
+ spec.bindir = 'exe'
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ['lib']
24
+
25
+ spec.add_development_dependency 'bundler', '~> 1.15'
26
+ spec.add_development_dependency 'rake', '~> 10.0'
27
+ spec.add_development_dependency 'rspec', '~> 3.0'
28
+ spec.add_development_dependency 'capybara'
29
+ spec.add_development_dependency 'selenium-webdriver'
30
+ spec.add_development_dependency 'rubocop'
31
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'timeout'
4
+ require 'ghost_pictures/api'
5
+ require 'ghost_pictures/capture'
6
+ require 'ghost_pictures/record'
7
+ require 'ghost_pictures/rspec_helpers'
8
+ require 'ghost_pictures/version'
9
+
10
+ module GhostPictures
11
+ extend API
12
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GhostPictures
4
+ module API
5
+ MSG = 'Pass the operation include Ajax requests as block argument'
6
+
7
+ def wait_for(path = nil, method: nil, count: 1)
8
+ raise(ArgumentError, MSG) unless block_given?
9
+
10
+ Record.reset!
11
+ yield
12
+ Timeout.timeout(Capybara.default_max_wait_time) do
13
+ loop { break if Record.select_if(method, path).size >= count }
14
+ end
15
+ end
16
+
17
+ # @see https://robots.thoughtbot.com/automatically-wait-for-ajax-with-capybara
18
+ def wait_for_jquery_ajax
19
+ Timeout.timeout(Capybara.default_max_wait_time) do
20
+ loop until finished_all_ajax_requests?
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def finished_all_ajax_requests?
27
+ page.evaluate_script('jQuery.active').zero?
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GhostPictures
4
+ Request = Struct.new(:id, :method, :path)
5
+
6
+ class Capture
7
+ def initialize(app)
8
+ @id = 0
9
+ @app = app
10
+ end
11
+
12
+ def call(env)
13
+ req = build_request(env)
14
+ Record.start(req)
15
+ @app.call(env)
16
+ ensure
17
+ Record.finish(req)
18
+ end
19
+
20
+ private
21
+
22
+ def build_request(env)
23
+ @id += 1
24
+ Request.new(@id, env['REQUEST_METHOD'].downcase.to_sym, env['PATH_INFO'])
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GhostPictures
4
+ module Record
5
+ class << self
6
+ def reset!
7
+ @started = []
8
+ @finished = []
9
+ end
10
+
11
+ def start(request)
12
+ started << request
13
+ end
14
+
15
+ def finish(request)
16
+ finished << request
17
+ end
18
+
19
+ def select_if(method, path)
20
+ finished_requests.select do |req|
21
+ (method.nil? || req.method == method) &&
22
+ (path.nil? || req.path == path)
23
+ end
24
+ end
25
+
26
+ def running?
27
+ !running_requests.empty?
28
+ end
29
+
30
+ private
31
+
32
+ def finished_requests
33
+ started & finished
34
+ end
35
+
36
+ def running_requests
37
+ started - finished
38
+ end
39
+
40
+ def started
41
+ @started ||= []
42
+ end
43
+
44
+ def finished
45
+ @finished ||= []
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GhostPictures
4
+ module RSpecHelpers
5
+ def wait_for_ajax(*args, &block)
6
+ GhostPictures.wait_for(*args, &block)
7
+ end
8
+
9
+ def wait_for_jquery_ajax
10
+ GhostPictures.wait_for_jquery_ajax
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GhostPictures
4
+ VERSION = '0.2.0'
5
+ end
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ghost_pictures
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - sinsoku
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-10-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: capybara
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: selenium-webdriver
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: rubocop
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
+ description: GhostPictures provides the feature to wait for Ajax requests with Capybara.
98
+ email:
99
+ - sinsoku.listy@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".rubocop.yml"
107
+ - ".travis.yml"
108
+ - Gemfile
109
+ - README.md
110
+ - Rakefile
111
+ - bin/console
112
+ - bin/setup
113
+ - ghost_pictures.gemspec
114
+ - lib/ghost_pictures.rb
115
+ - lib/ghost_pictures/api.rb
116
+ - lib/ghost_pictures/capture.rb
117
+ - lib/ghost_pictures/record.rb
118
+ - lib/ghost_pictures/rspec_helpers.rb
119
+ - lib/ghost_pictures/version.rb
120
+ homepage: https://github.com/sinsoku/ghost_pictures
121
+ licenses: []
122
+ metadata: {}
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 2.6.13
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: GhostPictures provides the feature to wait for Ajax requests with Capybara.
143
+ test_files: []