0.0
No release in over 3 years
Low commit activity in last 3 years
test_selector can be used to find specific elements in your tests without adding css variables or other html elements to your production environment
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

~> 1.10.0
>= 5.0
 Project Readme

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.