An open API service indexing awesome lists of open source software.

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!

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", CommentWidget

def 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"
end

def 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