https://github.com/emilebosch/capybara-map
Tired of writing nested awkward nested capybara specs? Take the component approach!
https://github.com/emilebosch/capybara-map
Last synced: 3 months ago
JSON representation
Tired of writing nested awkward nested capybara specs? Take the component approach!
- Host: GitHub
- URL: https://github.com/emilebosch/capybara-map
- Owner: emilebosch
- Created: 2015-07-07T07:03:41.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2023-04-11T22:03:30.000Z (about 2 years ago)
- Last Synced: 2025-01-14T03:35:26.006Z (5 months ago)
- Language: Ruby
- Homepage:
- Size: 9.77 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Capybara Map
An attempt to bring a bit of structure in capybara testing, by synchronizing
conventions on partials naming, css naming, and accessing models from the DOM.This is handy when you have complicated dom object such as activity feeds that you need
to have tested.Instead of doing complicated capybara finder stuff you can now just do:
```ruby
activity = AcitivtyDom.first
comment = activity.comments.first
commment.body.should "This is my fluffy cat."
comment.like!
```In this case the map for this looks like:
```ruby
class ActivityDom < Map
text :name, ".panel-heading strong a"
widget :like_button, ".panel-heading .mod-like-button", LikeButtonWidget
widgets :comments, ".mod-comment", CommentWidgetdef comment(text)
elm.fill_in "comment_body", with: text
elm.find(".comment-textfield").native.send_keys(:enter)
end
end
```As you can see it embeds a couple of other maps, the like and the comment widget:
```ruby
class CommentMap < Map
text :body, "p"
element :manager, ".label-primary"
widget :like_button, ".mod-like-button", LikeButtonWidget
end
```and
```ruby
class LikeButtonMap < Map
text :count, ".count"def like
elm.click_link "Like"
enddef unlike
elm.click_link "Unlike"
end
end
```By using these maps you can easily access your DOM and perform operations on them.
## Conventions
## To run
```
bundle
bundle exec ruby test.rb
```## Mapping