rspec-tapas 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +86 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +18 -0
- data/Rakefile +50 -0
- data/VERSION +1 -0
- data/lib/rspec-tapas.rb +10 -0
- data/lib/rspec_extensions/behavior_dsl.rb +28 -0
- data/lib/rspec_extensions/date_helpers.rb +19 -0
- data/lib/rspec_extensions/downloads_helpers.rb +37 -0
- data/lib/rspec_extensions/feature_helpers.rb +19 -0
- data/lib/rspec_extensions/get_message_part.rb +24 -0
- data/lib/rspec_extensions/invoke_task.rb +24 -0
- data/lib/rspec_extensions/json_response.rb +19 -0
- data/lib/rspec_extensions/locators/find_table_row.rb +107 -0
- data/lib/rspec_extensions/matchers/have_table_row.rb +38 -0
- data/lib/rspec_extensions/stub_env.rb +17 -0
- data/lib/rspec_extensions/view_page.rb +14 -0
- metadata +134 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f10e4f1e41b47b59254485d54f9127440531b951
|
4
|
+
data.tar.gz: 427281a46f534e80876cd432c88d8b4e4df2a192
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 519c3fdb1e282ea48f8139c6ec229e67c3ab479facf636cb9cfbc4490bce79775343948353e9c2ca808dbdfd865d23fa9dfe614fee55b771409e9279c7ef2ccc
|
7
|
+
data.tar.gz: db3cac2a8cbf0bc892626c2d15f88b4ddbd386b36bedf442c99d4d4c03bb62524ce10ff374e93dc8eff667aa9403a34baffec11504e8f3692293e471049894b7
|
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "shoulda", ">= 0"
|
10
|
+
gem "rdoc", "~> 3.12"
|
11
|
+
gem "bundler", "~> 1.0"
|
12
|
+
gem "juwelier", "~> 2.1.0"
|
13
|
+
gem "simplecov", ">= 0"
|
14
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activesupport (5.2.0)
|
5
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
6
|
+
i18n (>= 0.7, < 2)
|
7
|
+
minitest (~> 5.1)
|
8
|
+
tzinfo (~> 1.1)
|
9
|
+
addressable (2.5.2)
|
10
|
+
public_suffix (>= 2.0.2, < 4.0)
|
11
|
+
builder (3.2.3)
|
12
|
+
concurrent-ruby (1.0.5)
|
13
|
+
descendants_tracker (0.0.4)
|
14
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
15
|
+
docile (1.3.1)
|
16
|
+
faraday (0.12.2)
|
17
|
+
multipart-post (>= 1.2, < 3)
|
18
|
+
git (1.4.0)
|
19
|
+
github_api (0.18.2)
|
20
|
+
addressable (~> 2.4)
|
21
|
+
descendants_tracker (~> 0.0.4)
|
22
|
+
faraday (~> 0.8)
|
23
|
+
hashie (~> 3.5, >= 3.5.2)
|
24
|
+
oauth2 (~> 1.0)
|
25
|
+
hashie (3.5.7)
|
26
|
+
highline (2.0.0)
|
27
|
+
i18n (1.0.1)
|
28
|
+
concurrent-ruby (~> 1.0)
|
29
|
+
json (1.8.6)
|
30
|
+
juwelier (2.1.3)
|
31
|
+
builder
|
32
|
+
bundler (>= 1.13)
|
33
|
+
git (>= 1.2.5)
|
34
|
+
github_api
|
35
|
+
highline (>= 1.6.15)
|
36
|
+
nokogiri (>= 1.5.10)
|
37
|
+
rake
|
38
|
+
rdoc
|
39
|
+
semver
|
40
|
+
jwt (1.5.6)
|
41
|
+
mini_portile2 (2.3.0)
|
42
|
+
minitest (5.11.3)
|
43
|
+
multi_json (1.13.1)
|
44
|
+
multi_xml (0.6.0)
|
45
|
+
multipart-post (2.0.0)
|
46
|
+
nokogiri (1.8.3)
|
47
|
+
mini_portile2 (~> 2.3.0)
|
48
|
+
oauth2 (1.4.0)
|
49
|
+
faraday (>= 0.8, < 0.13)
|
50
|
+
jwt (~> 1.0)
|
51
|
+
multi_json (~> 1.3)
|
52
|
+
multi_xml (~> 0.5)
|
53
|
+
rack (>= 1.2, < 3)
|
54
|
+
public_suffix (3.0.2)
|
55
|
+
rack (2.0.5)
|
56
|
+
rake (12.3.1)
|
57
|
+
rdoc (3.12.2)
|
58
|
+
json (~> 1.4)
|
59
|
+
semver (1.0.1)
|
60
|
+
shoulda (3.5.0)
|
61
|
+
shoulda-context (~> 1.0, >= 1.0.1)
|
62
|
+
shoulda-matchers (>= 1.4.1, < 3.0)
|
63
|
+
shoulda-context (1.2.2)
|
64
|
+
shoulda-matchers (2.8.0)
|
65
|
+
activesupport (>= 3.0.0)
|
66
|
+
simplecov (0.16.1)
|
67
|
+
docile (~> 1.1)
|
68
|
+
json (>= 1.8, < 3)
|
69
|
+
simplecov-html (~> 0.10.0)
|
70
|
+
simplecov-html (0.10.2)
|
71
|
+
thread_safe (0.3.6)
|
72
|
+
tzinfo (1.2.5)
|
73
|
+
thread_safe (~> 0.1)
|
74
|
+
|
75
|
+
PLATFORMS
|
76
|
+
ruby
|
77
|
+
|
78
|
+
DEPENDENCIES
|
79
|
+
bundler (~> 1.0)
|
80
|
+
juwelier (~> 2.1.0)
|
81
|
+
rdoc (~> 3.12)
|
82
|
+
shoulda
|
83
|
+
simplecov
|
84
|
+
|
85
|
+
BUNDLED WITH
|
86
|
+
1.16.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2018 Błażej Kosmowski
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
= rspec-tapas
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to rspec-tapas
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
9
|
+
* Fork the project.
|
10
|
+
* Start a feature/bugfix branch.
|
11
|
+
* Commit and push until you are happy with your contribution.
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2018 Błażej Kosmowski. See LICENSE.txt for
|
18
|
+
further details.
|
data/Rakefile
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
require 'juwelier'
|
14
|
+
Juwelier::Tasks.new do |gem|
|
15
|
+
# gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
|
16
|
+
gem.name = "rspec-tapas"
|
17
|
+
gem.homepage = "http://github.com/Selleo/rspec-tapas"
|
18
|
+
gem.license = "MIT"
|
19
|
+
gem.summary = "A selection of small rSpec extensions"
|
20
|
+
gem.description = "A selection of small rSpec extensions"
|
21
|
+
gem.email = "b.kosmowski@selleo.com"
|
22
|
+
gem.authors = ["Błażej Kosmowski"]
|
23
|
+
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Juwelier::RubygemsDotOrgTasks.new
|
27
|
+
require 'rake/testtask'
|
28
|
+
Rake::TestTask.new(:test) do |test|
|
29
|
+
test.libs << 'lib' << 'test'
|
30
|
+
test.pattern = 'test/**/test_*.rb'
|
31
|
+
test.verbose = true
|
32
|
+
end
|
33
|
+
|
34
|
+
desc "Code coverage detail"
|
35
|
+
task :simplecov do
|
36
|
+
ENV['COVERAGE'] = "true"
|
37
|
+
Rake::Task['test'].execute
|
38
|
+
end
|
39
|
+
|
40
|
+
task :default => :test
|
41
|
+
|
42
|
+
require 'rdoc/task'
|
43
|
+
Rake::RDocTask.new do |rdoc|
|
44
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
45
|
+
|
46
|
+
rdoc.rdoc_dir = 'rdoc'
|
47
|
+
rdoc.title = "rspec-tapas #{version}"
|
48
|
+
rdoc.rdoc_files.include('README*')
|
49
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
50
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/lib/rspec-tapas.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'rspec_extensions/behavior_dsl'
|
2
|
+
require 'rspec_extensions/downloads_helpers'
|
3
|
+
require 'rspec_extensions/feature_helpers'
|
4
|
+
require 'rspec_extensions/get_message_part'
|
5
|
+
require 'rspec_extensions/invoke_task'
|
6
|
+
require 'rspec_extensions/json_response'
|
7
|
+
require 'rspec_extensions/stub_env'
|
8
|
+
require 'rspec_extensions/view_page'
|
9
|
+
require 'rspec_extensions/matchers/have_table_row'
|
10
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module RspecExtensions
|
2
|
+
module BehaviorDSL
|
3
|
+
def behavior(name)
|
4
|
+
metadata[:description_args].push(name)
|
5
|
+
refresh_description
|
6
|
+
yield
|
7
|
+
metadata[:description_args].pop
|
8
|
+
refresh_description
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def refresh_description
|
14
|
+
metadata[:description] = metadata[:description_args].join(' ')
|
15
|
+
metadata[:full_description] = \
|
16
|
+
[metadata[:example_group][:full_description]].
|
17
|
+
concat(metadata[:description_args]).join(' ')
|
18
|
+
end
|
19
|
+
|
20
|
+
def metadata
|
21
|
+
RSpec.current_example.metadata
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
RSpec.configure do |config|
|
27
|
+
config.include RspecExtensions::BehaviorDSL, type: :feature
|
28
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module RspecExtensions
|
2
|
+
module DateHelpers
|
3
|
+
def at_date(*parts)
|
4
|
+
travel_to(Date.new(*parts)) do
|
5
|
+
yield
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def freeze_time
|
10
|
+
travel_to(Time.current) do
|
11
|
+
yield
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
RSpec.configure do |config|
|
18
|
+
config.include RspecExtensions::DateHelpers
|
19
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module RspecExtensions
|
2
|
+
module DownloadsHelpers
|
3
|
+
DOWNLOADS_PATH = Rails.root.join('tmp').freeze
|
4
|
+
|
5
|
+
def allow_file_downloads(page)
|
6
|
+
bridge = page.driver.browser.send(:bridge)
|
7
|
+
path = '/session/:session_id/chromium/send_command'
|
8
|
+
path[':session_id'] = bridge.session_id
|
9
|
+
bridge.http.call(
|
10
|
+
:post,
|
11
|
+
path,
|
12
|
+
cmd: 'Page.setDownloadBehavior',
|
13
|
+
params: { behavior: 'allow', downloadPath: DOWNLOADS_PATH }
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
def downloaded_file_contents(name)
|
18
|
+
read_attempt = 1
|
19
|
+
|
20
|
+
begin
|
21
|
+
File.read(Support::DownloadsHelpers::DOWNLOADS_PATH.join(name))
|
22
|
+
rescue Errno::ENOENT => exception
|
23
|
+
if read_attempt < 3
|
24
|
+
read_attempt += 1
|
25
|
+
sleep(Capybara.default_max_wait_time)
|
26
|
+
retry
|
27
|
+
else
|
28
|
+
raise exception
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
RSpec.configure do |config|
|
36
|
+
config.include RspecExtensions::DownloadsHelpers, type: :feature
|
37
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module RspecExtensions
|
2
|
+
module FeatureHelpers
|
3
|
+
def display_logs
|
4
|
+
puts page.driver.browser.manage.logs.get('browser')
|
5
|
+
end
|
6
|
+
|
7
|
+
def ss
|
8
|
+
page.save_and_open_screenshot
|
9
|
+
end
|
10
|
+
|
11
|
+
def reload_page
|
12
|
+
page.evaluate_script('window.location.reload()')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
RSpec.configure do |config|
|
18
|
+
config.include RspecExtensions::FeatureHelpers, type: :feature
|
19
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module RspecExtensions
|
2
|
+
module GetMessagePart
|
3
|
+
def get_message_part(mail, content_type)
|
4
|
+
is_multipart = mail.body.parts.present?
|
5
|
+
if is_multipart
|
6
|
+
mail.body.parts.detect { |part| part.content_type.match(content_type) }.body.raw_source
|
7
|
+
else
|
8
|
+
mail.body.raw_source
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def html_part(mail)
|
13
|
+
get_message_part(mail, /html/)
|
14
|
+
end
|
15
|
+
|
16
|
+
def text_part(mail)
|
17
|
+
get_message_part(mail, /plain/)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
RSpec.configure do |config|
|
23
|
+
config.include RspecExtensions::GetMessagePart, type: :mailer
|
24
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# https://robots.thoughtbot.com/test-rake-tasks-like-a-boss
|
2
|
+
module RspecExtensions
|
3
|
+
module InvokeTask
|
4
|
+
def invoke_task(name, options = {})
|
5
|
+
task_path =
|
6
|
+
metadata[:file_path].match(%r{spec/(?<file_path>.*)_spec\.rb})[:file_path]
|
7
|
+
loaded_files_excluding_current_rake_file =
|
8
|
+
$".reject { |file| file == Rails.root.join("#{task_path}.rake").to_s }
|
9
|
+
Rake.application = Rake::Application.new
|
10
|
+
Rake.application.rake_require(
|
11
|
+
task_path,
|
12
|
+
[Rails.root.to_s],
|
13
|
+
loaded_files_excluding_current_rake_file
|
14
|
+
)
|
15
|
+
Rake::Task.define_task(:environment)
|
16
|
+
task = Rake.application[name]
|
17
|
+
task.execute(options)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
RSpec.configure do |config|
|
23
|
+
config.include RspecExtensions::InvokeTask, type: :rake
|
24
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module RspecExtensions
|
2
|
+
module JsonResponse
|
3
|
+
def json_response
|
4
|
+
parsed_json = JSON.parse(response.body)
|
5
|
+
if parsed_json.is_a?(Hash)
|
6
|
+
HashWithIndifferentAccess.new(parsed_json)
|
7
|
+
else
|
8
|
+
parsed_json.map do |entry|
|
9
|
+
entry.is_a?(Hash) ? HashWithIndifferentAccess.new(entry) : entry
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
RSpec.configure do |config|
|
17
|
+
config.include RspecExtensions::JsonResponse, type: :request
|
18
|
+
config.include RspecExtensions::JsonResponse, type: :controller
|
19
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'rspec/expectations'
|
2
|
+
|
3
|
+
module FindTableRow
|
4
|
+
def find_table_row(*column_expectations)
|
5
|
+
expectations_hash = column_expectations.extract_options!
|
6
|
+
TableRowFinder.call(self, expectations_hash)
|
7
|
+
end
|
8
|
+
|
9
|
+
def find_table_cell(column_index_or_name, *column_expectations)
|
10
|
+
expectations_hash = column_expectations.extract_options!
|
11
|
+
finder = TableRowFinder.new(self, expectations_hash)
|
12
|
+
row = finder.call
|
13
|
+
column_index = finder.header_key_to_column_index(column_index_or_name)
|
14
|
+
row.find(:xpath, "./td[#{column_index + 1}]")
|
15
|
+
end
|
16
|
+
|
17
|
+
class TableRowFinder
|
18
|
+
def initialize(page, column_expectations)
|
19
|
+
@page = page
|
20
|
+
@column_expectations = column_expectations
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.call(page, column_expectations)
|
24
|
+
new(page, column_expectations).call
|
25
|
+
end
|
26
|
+
|
27
|
+
def call
|
28
|
+
verify_table_ambiguity!
|
29
|
+
find_row
|
30
|
+
end
|
31
|
+
|
32
|
+
def header_key_to_column_index(key)
|
33
|
+
key.is_a?(String) ? existing_header_labels.index(key) : key
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
attr_reader :page, :column_expectations
|
39
|
+
|
40
|
+
def normalized_column_expectations
|
41
|
+
@normalized_column_expectations ||= begin
|
42
|
+
if column_expectations.is_a? Array
|
43
|
+
column_expectations.each_with_index.each_with_object({}) do |(value, index), result|
|
44
|
+
result[index] = value
|
45
|
+
end
|
46
|
+
else
|
47
|
+
ensure_headers_presence!
|
48
|
+
|
49
|
+
column_expectations.transform_keys do |key|
|
50
|
+
header_key_to_column_index(key)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def verify_table_ambiguity!
|
57
|
+
if page.all('table').count > 1
|
58
|
+
raise Capybara::Ambiguous, 'Ambiguous match, there is more than one table'
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def existing_header_labels
|
63
|
+
@existing_header_labels ||= page.all('thead > tr > th').map(&:text)
|
64
|
+
end
|
65
|
+
|
66
|
+
def ensure_headers_presence!
|
67
|
+
expected_header_labels = column_expectations.keys.select { |v| v.is_a? String }
|
68
|
+
missing_headers = expected_header_labels - existing_header_labels
|
69
|
+
|
70
|
+
if missing_headers.present?
|
71
|
+
raise Capybara::ElementNotFound, "Could not find columns: #{missing_headers.join(', ')}"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def find_row
|
76
|
+
matching_rows = page.all('tbody > tr').find_all do |row|
|
77
|
+
normalized_column_expectations.all? do |column_index, expectation|
|
78
|
+
cell = row.find(:xpath, "./td[#{column_index + 1}]")
|
79
|
+
compare(cell, expectation)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
if matching_rows.count > 1
|
84
|
+
raise Capybara::Ambiguous, "Ambiguous match, found #{matching_rows.count} rows"
|
85
|
+
elsif matching_rows.empty?
|
86
|
+
raise Capybara::ElementNotFound, "Row with #{formatted_expected_attributes} not found"
|
87
|
+
else
|
88
|
+
matching_rows.first
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def formatted_expected_attributes
|
93
|
+
if column_expectations.is_a?(Array)
|
94
|
+
column_expectations.join(', ')
|
95
|
+
else
|
96
|
+
column_expectations.map do |header_name, expected_value|
|
97
|
+
"#{header_name}: #{expected_value}"
|
98
|
+
end.join(', ')
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def compare(cell, expectation)
|
103
|
+
return expectation.matches?(cell) if expectation.respond_to?(:matches?)
|
104
|
+
cell.text.strip == expectation.to_s.strip
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require_relative '../locators/find_table_row.rb'
|
2
|
+
require 'rspec/expectations'
|
3
|
+
|
4
|
+
Capybara::Session.include FindTableRow
|
5
|
+
Capybara::Node::Simple.include FindTableRow
|
6
|
+
|
7
|
+
RSpec::Matchers.define :have_table_row do |*expected|
|
8
|
+
match do |page|
|
9
|
+
with_delay do
|
10
|
+
page.find_table_row(*expected)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
match_when_negated do
|
15
|
+
page.find_table_row(*expected)
|
16
|
+
false
|
17
|
+
rescue Capybara::ElementNotFound
|
18
|
+
true
|
19
|
+
end
|
20
|
+
|
21
|
+
failure_message do
|
22
|
+
@failure_message
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def with_delay
|
28
|
+
Timeout.timeout(Capybara.default_max_wait_time) do
|
29
|
+
yield
|
30
|
+
rescue => error
|
31
|
+
@failure_message = error.message
|
32
|
+
sleep(1)
|
33
|
+
retry
|
34
|
+
end
|
35
|
+
rescue Timeout::Error
|
36
|
+
false
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module RspecExRspecExtensionstensions
|
2
|
+
module StubEnv
|
3
|
+
def stub_env(name, value)
|
4
|
+
allow(ENV).to receive(:fetch).and_wrap_original do |m, *args|
|
5
|
+
if args.first == name
|
6
|
+
value
|
7
|
+
else
|
8
|
+
m.call(*args)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
RSpec.configure do |config|
|
16
|
+
config.include RspecExtensions::StubEnv
|
17
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module RspecExtensions
|
2
|
+
module ViewPage
|
3
|
+
def page
|
4
|
+
Capybara.string(rendered)
|
5
|
+
end
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
RSpec.configure do |config|
|
10
|
+
config.include RspecExtensions::ViewPage, type: :view
|
11
|
+
config.around(:each, type: :view) do |example|
|
12
|
+
without_partial_double_verification { example.run }
|
13
|
+
end
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec-tapas
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Błażej Kosmowski
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-06-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: shoulda
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rdoc
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.12'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.12'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: juwelier
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.1.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.1.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
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
|
+
description: A selection of small rSpec extensions
|
84
|
+
email: b.kosmowski@selleo.com
|
85
|
+
executables: []
|
86
|
+
extensions: []
|
87
|
+
extra_rdoc_files:
|
88
|
+
- LICENSE.txt
|
89
|
+
- README.rdoc
|
90
|
+
files:
|
91
|
+
- ".document"
|
92
|
+
- Gemfile
|
93
|
+
- Gemfile.lock
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.rdoc
|
96
|
+
- Rakefile
|
97
|
+
- VERSION
|
98
|
+
- lib/rspec-tapas.rb
|
99
|
+
- lib/rspec_extensions/behavior_dsl.rb
|
100
|
+
- lib/rspec_extensions/date_helpers.rb
|
101
|
+
- lib/rspec_extensions/downloads_helpers.rb
|
102
|
+
- lib/rspec_extensions/feature_helpers.rb
|
103
|
+
- lib/rspec_extensions/get_message_part.rb
|
104
|
+
- lib/rspec_extensions/invoke_task.rb
|
105
|
+
- lib/rspec_extensions/json_response.rb
|
106
|
+
- lib/rspec_extensions/locators/find_table_row.rb
|
107
|
+
- lib/rspec_extensions/matchers/have_table_row.rb
|
108
|
+
- lib/rspec_extensions/stub_env.rb
|
109
|
+
- lib/rspec_extensions/view_page.rb
|
110
|
+
homepage: http://github.com/Selleo/rspec-tapas
|
111
|
+
licenses:
|
112
|
+
- MIT
|
113
|
+
metadata: {}
|
114
|
+
post_install_message:
|
115
|
+
rdoc_options: []
|
116
|
+
require_paths:
|
117
|
+
- lib
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
requirements: []
|
129
|
+
rubyforge_project:
|
130
|
+
rubygems_version: 2.6.14
|
131
|
+
signing_key:
|
132
|
+
specification_version: 4
|
133
|
+
summary: A selection of small rSpec extensions
|
134
|
+
test_files: []
|