Skip to content
Test Selector for ruby
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin
lib
test
.gitignore
CHANGELOG.md
Gemfile
Gemfile.lock
MIT-LICENSE
README.md
Rakefile
test_selector.gemspec

README.md

TestSelector

Based on TestSelector for Elixir, a gem that adds a test-selector to the HTML so it can be found in the tests.

Usage

After installing this gem the views have a helper method test_selector that can be used as:

<!--- app/views/some/view.erb --->
<p <%= test_selector "description", 1 %>the description of entity 1</p>

<p <%= test_selector "description", 2 %>the description of entity 2</p>

That will result in:

<p test-selector="_app_views_some_view_erb__description" test-value="1">the description of entity 1</p>

<p test-selector="_app_views_some_view_erb__description" test-value="2">the description of entity 2</p>

In the test this can be found with:

it "assert the second description" do
  ... # some setup

  test_part = test_selector(path, "description", 1)
  expect(find_test_selector page.body, test_part).to have_content "the description of entity 2"
end

Installation

Add this line to your application's Gemfile:

  • Dependencie: Rails

Add to the Gemfile

gem 'test_selector'

Execute:

$ bundle

include in the test framework you're using, for RSpec:

require 'test_selector'

RSpec.configure do |config|
  ...

  config.include TestSelector::TestHelpers
end

License

The gem is available as open source under the terms of the MIT License.

You can’t perform that action at this time.