Skip to content
Permalink
Browse files

Initial code

  • Loading branch information...
luke-hill committed Jun 24, 2019
1 parent a778bbc commit 9c38c16b7801664abd5c16ca945fcd827a4bf92d
@@ -0,0 +1,28 @@
require: rubocop-performance

AllCops:
TargetRubyVersion: 2.3

Metrics/LineLength:
Max: 100
IgnoredPatterns:
- '^Given'
- '^When'
- '^Then'

Style/RegexpLiteral:
EnforcedStyle: slashes
AllowInnerSlashes: true

BlockLength:
Exclude:
- './spec/**/*_spec.rb'
- 'site_prism.gemspec'

Style/TrailingCommaInHashLiteral:
EnforcedStyleForMultiline: comma
Enabled: true

Style/TrailingCommaInArrayLiteral:
EnforcedStyleForMultiline: comma
Enabled: true
@@ -0,0 +1 @@
ruby-2.3
@@ -0,0 +1,35 @@
language: ruby

sudo: required

dist: xenial

rvm:
- 2.4
- 2.5
- 2.6
- ruby-head

env:
- browser=chrome
- browser=firefox

gemfile:
- Gemfile

addons:
chrome: stable
firefox: latest

before_install:
- gem install bundler -v '< 2'

services:
- xvfb

script:
- bundle exec rake

branches:
only:
- master
@@ -0,0 +1,21 @@
<!-- #392 - May 10th - Last update to this document -->
## [Unreleased]
### Removed

### Added

### Changed

### Fixed

## [0.1] - 2019-xx-xx
### Added
- Base code from previous repo with some extra puts/warn statements
([luke-hill])

<!-- Releases -->
[Unreleased]: https://github.com/natritmeyer/site_prism/compare/v0.1...master
[0.1]: https://github.com/natritmeyer/site_prism/compare/abc123...v0.1

<!-- Contributors in chronological order -->
[luke-hill]: https://github.com/luke-hill
@@ -0,0 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gemspec
@@ -0,0 +1,29 @@
# SitePrism All There Hacking setup

To successfully get this gem running locally and to hack on it, you need to fork the repo and have
`geckodriver` and/or `chromedriver` downloaded

```bash
$ git clone git@github.com:site-prism/site_prism-all_there.git
$ cd site_prism-all_there
$ bundle
```

Hacking commands you may need are ...

```bash
$ bundle exec rake cukes # Run feature tests on firefox (Default browser)
$ bundle exec rake cukes browser=chrome # Run feature tests on chrome
$ bundle exec rake specs # Run all rspec tests
$ bundle exec rake # Runs feature tests on firefox, then specs, then runs rubocop
```

- Write your code. Make sure to add unit / feature tests AND documentation (If appropriate)
- Run `bundle exec rake` and ensure it passes
- Submit a pull request

Happy Testing / Developing!

Cheers,

The SitePrism Team
@@ -0,0 +1,28 @@
Copyright (c) 2018-2019, The SitePrism team

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,15 @@
# frozen_string_literal: true

task :cukes do
system('bundle exec cucumber') || raise('Cukes failed')
end

task :specs do
system('bundle exec rspec') || raise('Specs failed')
end

task :cops do
system('bundle exec rubocop') || raise('Cops failed')
end

task default: %i[specs cukes cops]
@@ -0,0 +1,76 @@
# frozen_string_literal: true

module SitePrism
class RecursionChecker
attr_reader :instance
private :instance

def initialize(instance)
@instance = instance
end

def all_there?
regular_items_all_there = expected_item_map.flatten.all? { |name| there?(name) }
return false unless regular_items_all_there

section_all_there =
section_classes_to_check.all?(&:all_there?)
return false unless section_all_there

# Returning this final check here is fine, as the previous two checks must
# have returned +true+ in order to hit this part of the method-call
sections_classes_to_check.all?(&:all_there?)
end

def expected_item_map
[
expected(mapped_items, :element),
expected(mapped_items, :elements),
expected(mapped_items, :section),
expected(mapped_items, :sections),
expected(mapped_items, :iframe),
]
end

def expected(_map, type)
mapped_items[type].select { |name| elements_to_check.include?(name) }
end

def section_classes_to_check
expected_item_map[2].map { |name| instance.send(name) }
end

def sections_classes_to_check
expected_item_map[3].map { |name| instance.send(name) }.flatten
end

private

# If the page or section has expected_items set, return expected_items that are mapped
# otherwise just return the list of all mapped_items
def elements_to_check
if _expected_items
SitePrism.logger.debug('Expected Items has been set.')
_mapped_items.select { |name| _expected_items.include?(name) }
else
_mapped_items
end
end

def _mapped_items
mapped_items.values.flatten.uniq
end

def _expected_items
instance.class.expected_items
end

def there?(name)
instance.send("has_#{name}?")
end

def mapped_items
@mapped_items ||= instance.class.mapped_items(legacy: false)
end
end
end
@@ -0,0 +1,5 @@
# frozen_string_literal: true

module SitePrism
VERSION = '0.1'
end
@@ -0,0 +1,6 @@
# frozen_string_literal: true

module SitePrism
autoload :ElementChecker, 'site_prism/element_checker'
autoload :RecursionChecker, 'site_prism/recursion_checker'
end
@@ -0,0 +1,32 @@
# frozen_string_literal: true

require './lib/site_prism/all_there/version'

Gem::Specification.new do |s|
s.name = 'site_prism-all_there'
s.version = SitePrism::AllThere::VERSION
s.required_ruby_version = '>= 2.3'
s.platform = Gem::Platform::RUBY
s.license = 'BSD-3-Clause'
s.authors = ['Luke Hill']
s.email = %w[lukehill_uk@hotmail.com]
s.homepage = 'https://github.com/site_prism/site_prism-all_there'
s.metadata = {
'bug_tracker_uri' => 'https://github.com/site_prism/site_prism-all_there/issues',
'changelog_uri' => 'https://github.com/site_prism/site_prism-all_there/blob/master/CHANGELOG.md',
'source_code_uri' => 'https://github.com/site_prism/site_prism-all_there',
}
s.summary = 'An extension to the SitePrism gem to allow you to use recursive checks on #all_there?'
s.description = 'SitePrism AllThere gives you a simple DSL in order to recursively query,
page/section/element structures on your page - exclusively for use with the SitePrism gem.'
s.files = Dir.glob('lib/**/*') + %w[LICENSE.md README.md]
s.require_path = 'lib'

s.add_development_dependency 'cucumber', ['~> 3.1']
s.add_development_dependency 'rake', ['~> 12.3']
s.add_development_dependency 'rspec', ['~> 3.8']
s.add_development_dependency 'rubocop', ['~> 0.67.0']
s.add_development_dependency 'rubocop-performance', ['~> 1.0.0']
s.add_development_dependency 'selenium-webdriver', ['~> 3.7']
s.add_development_dependency 'site_prism', ['~> 3.2']
end

0 comments on commit 9c38c16

Please sign in to comment.
You can’t perform that action at this time.