Skip to content

Commit

Permalink
Respect expected items when using present (#158)
Browse files Browse the repository at this point in the history
* Respect expected items when using elements present

* Optimisation - intersection over inclusion

* Optimise element checker to use sub gem

* Add changelog
  • Loading branch information
luke-hill authored Jun 23, 2023
1 parent 91a19f1 commit 9d4fdaa
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
(No more hard-coded mocked responses, meaning our unit tests are **much more** realistic!)
([luke-hill])

- Optimised some recursion logic to use the `site_prism-all_there` sub-gem ([luke-hill])

### Fixed
- `#elements_present` properly respects `.expected_items` when set ([luke-hill])

## [4.0.2] - 2023-05-23
### Fixed
Expand Down
17 changes: 2 additions & 15 deletions lib/site_prism/element_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def all_there?(recursion: :none)
#
# @return [Array]
def elements_present
_mapped_items.select { |name| there?(name) }
elements_to_check.select { |name| there?(name) }
end

# Returns each element that is not currently present inside the scope being tested
Expand All @@ -52,20 +52,7 @@ def elements_missing
private

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
self.class.mapped_items.values.flatten.uniq
end

def _expected_items
self.class.expected_items
SitePrism::AllThere::ExpectedItems.new(self).send(:mapped_checklist)
end

def there?(name)
Expand Down

0 comments on commit 9d4fdaa

Please sign in to comment.