cuprite-downloads 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/main.yml +18 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +34 -0
- data/LICENSE.txt +21 -0
- data/README.md +44 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/cuprite-downloads.gemspec +34 -0
- data/lib/cuprite/downloads/cucumber.rb +17 -0
- data/lib/cuprite/downloads/version.rb +7 -0
- data/lib/cuprite/downloads.rb +47 -0
- metadata +59 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bef81779b6915300ccf8f2b3074109e4751fca2d32a41615b1a778ddb2e56bc2
|
4
|
+
data.tar.gz: e330311c003c579d1b03cb398e019bda11129c62637719cd1e6b05370d00b3bb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5b2a412dc1088560c1db3b01b24d2f5fce576ecd4a1f9b6eb03ec4464a343a71cbaedd7a798be0d43fc04fb72e431a4baf49f8e22d2f1da121086ebc26296f8c
|
7
|
+
data.tar.gz: e883cf893cfc75419c8a88eee92c774960d2f341d058ed38f81e708adb9fe8d8db2a8c459a9c9006126313df0ef5997d75d486df25b3902bc275b4f9a947c779
|
@@ -0,0 +1,18 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on: [push,pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
steps:
|
9
|
+
- uses: actions/checkout@v2
|
10
|
+
- name: Set up Ruby
|
11
|
+
uses: ruby/setup-ruby@v1
|
12
|
+
with:
|
13
|
+
ruby-version: 3.0.0
|
14
|
+
- name: Run the default task
|
15
|
+
run: |
|
16
|
+
gem install bundler -v 2.2.3
|
17
|
+
bundle install
|
18
|
+
bundle exec rake
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
cuprite-downloads (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.4.4)
|
10
|
+
rake (13.0.6)
|
11
|
+
rspec (3.10.0)
|
12
|
+
rspec-core (~> 3.10.0)
|
13
|
+
rspec-expectations (~> 3.10.0)
|
14
|
+
rspec-mocks (~> 3.10.0)
|
15
|
+
rspec-core (3.10.1)
|
16
|
+
rspec-support (~> 3.10.0)
|
17
|
+
rspec-expectations (3.10.1)
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
+
rspec-support (~> 3.10.0)
|
20
|
+
rspec-mocks (3.10.2)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.10.0)
|
23
|
+
rspec-support (3.10.2)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
x86_64-linux
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
cuprite-downloads!
|
30
|
+
rake (~> 13.0)
|
31
|
+
rspec (~> 3.0)
|
32
|
+
|
33
|
+
BUNDLED WITH
|
34
|
+
2.2.3
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Micah Geisel
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# Cuprite::Downloads
|
2
|
+
|
3
|
+
A file download API for Cuprite
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
# Gemfile
|
11
|
+
gem 'cuprite-downloads'
|
12
|
+
```
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
# features/support/env.rb
|
16
|
+
require "capybara/cuprite"
|
17
|
+
require "cuprite/downloads/cucumber"
|
18
|
+
```
|
19
|
+
|
20
|
+
_TODO: other test runner integration_
|
21
|
+
|
22
|
+
This gem adds a `page.driver.downloads` method, which returns an instance of `Capybara::Cuprite::Downloads`. This object has a few useful methods:
|
23
|
+
|
24
|
+
* `#filenames`: an array of all the downloaded filenames
|
25
|
+
* `#[](filename)`: an open File handle to the specified filename
|
26
|
+
|
27
|
+
These methods also exist, but are mostly only useful in hooking it up to Capybara and your test runner, which is taken care of in the `cuprite/downloads/cucumber` file
|
28
|
+
|
29
|
+
* `#pathname`: The directory where the downloads are saved, usualy something like `tmp/capybara/1640698858474/downloads`. The number is a unique key to ensure concurrent file downloads don't collide.
|
30
|
+
* `#reset`: Empties the directory above. This is automatically called after each cucumber scenario
|
31
|
+
|
32
|
+
## Development
|
33
|
+
|
34
|
+
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.
|
35
|
+
|
36
|
+
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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/cuprite-downloads.
|
41
|
+
|
42
|
+
## License
|
43
|
+
|
44
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
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 "cuprite/downloads"
|
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,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/cuprite/downloads/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "cuprite-downloads"
|
7
|
+
spec.version = Cuprite::Downloads::VERSION
|
8
|
+
spec.authors = ["Micah Geisel"]
|
9
|
+
spec.email = ["micah@botandrose.com"]
|
10
|
+
|
11
|
+
spec.summary = "Adds file download capabilities to Cuprite"
|
12
|
+
spec.homepage = "https://github.com/botandrose/cuprite-downloads"
|
13
|
+
spec.license = "MIT"
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
15
|
+
|
16
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
17
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
18
|
+
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
23
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
24
|
+
end
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
# Uncomment to register a new dependency of your gem
|
30
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
31
|
+
|
32
|
+
# For more information and examples about making a new gem, checkout our
|
33
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
34
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "cuprite/downloads"
|
2
|
+
require "capybara/cuprite/driver"
|
3
|
+
|
4
|
+
Capybara::Cuprite::Driver.class_eval do
|
5
|
+
def downloads
|
6
|
+
@downloads ||= Capybara::Cuprite::Downloads.new
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
Capybara.save_path = Capybara::Cuprite::Downloads.pathname
|
11
|
+
|
12
|
+
Before do
|
13
|
+
if downloads = page.driver.try(:downloads)
|
14
|
+
downloads.reset
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "fileutils"
|
4
|
+
require "capybara"
|
5
|
+
|
6
|
+
module Capybara
|
7
|
+
module Cuprite
|
8
|
+
class Downloads
|
9
|
+
class NotFound < Capybara::ExpectationNotMet; end
|
10
|
+
|
11
|
+
def self.pathname
|
12
|
+
@pathname ||= begin
|
13
|
+
unique_id = Time.now.strftime('%s%L') # to keep concurrent runs from colliding
|
14
|
+
Capybara.save_path.join(unique_id, "downloads")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def pathname
|
19
|
+
self.class.pathname
|
20
|
+
end
|
21
|
+
|
22
|
+
def dir
|
23
|
+
pathname.to_s
|
24
|
+
end
|
25
|
+
|
26
|
+
def reset
|
27
|
+
FileUtils.rm_rf(dir)
|
28
|
+
FileUtils.mkdir_p(dir)
|
29
|
+
end
|
30
|
+
|
31
|
+
def filenames
|
32
|
+
pathname.entries.reject(&:directory?).map(&:to_s)
|
33
|
+
end
|
34
|
+
|
35
|
+
def [] filename
|
36
|
+
Capybara.current_session.document.synchronize do
|
37
|
+
begin
|
38
|
+
File.open(pathname.join(filename))
|
39
|
+
rescue Errno::ENOENT
|
40
|
+
raise NotFound.new("Couldn't find #{filename} in #{filenames}")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cuprite-downloads
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Micah Geisel
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-12-28 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
- micah@botandrose.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".github/workflows/main.yml"
|
21
|
+
- ".gitignore"
|
22
|
+
- ".rspec"
|
23
|
+
- Gemfile
|
24
|
+
- Gemfile.lock
|
25
|
+
- LICENSE.txt
|
26
|
+
- README.md
|
27
|
+
- Rakefile
|
28
|
+
- bin/console
|
29
|
+
- bin/setup
|
30
|
+
- cuprite-downloads.gemspec
|
31
|
+
- lib/cuprite/downloads.rb
|
32
|
+
- lib/cuprite/downloads/cucumber.rb
|
33
|
+
- lib/cuprite/downloads/version.rb
|
34
|
+
homepage: https://github.com/botandrose/cuprite-downloads
|
35
|
+
licenses:
|
36
|
+
- MIT
|
37
|
+
metadata:
|
38
|
+
homepage_uri: https://github.com/botandrose/cuprite-downloads
|
39
|
+
source_code_uri: https://github.com/botandrose/cuprite-downloads
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 2.3.0
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
requirements: []
|
55
|
+
rubygems_version: 3.2.3
|
56
|
+
signing_key:
|
57
|
+
specification_version: 4
|
58
|
+
summary: Adds file download capabilities to Cuprite
|
59
|
+
test_files: []
|