Rspec. assert_select deprecated?

630 views
Skip to first unread message

Ralph Shnelvar

unread,
Jul 14, 2017, 4:58:56 AM7/14/17
to Ruby on Rails: Talk
In https://apidock.com/rails/ActionController/Assertions/SelectorAssertions/assert_select I see that  assert_select was deprecated.

Yes, when I run
rails generate scaffold SqlStatement \
  title
:text{120} \
  description
:text \
  sql_stmt
:text

I find the following code generated in ~/spec/views/sql_statements/index.html.erb_spec.rb
require 'rails_helper'

RSpec.describe "sql_statements/index", type: :view do
  before
(:each) do
    assign
(:sql_statements, [
     
SqlStatement.create!(
       
:title => "MyText",
       
:description => "MyText",
       
:sql_stmt => "MyText"
     
),
     
SqlStatement.create!(
       
:title => "MyText",
       
:description => "MyText",
       
:sql_stmt => "MyText"
     
)
   
])
 
end

  it
"renders a list of sql_statements" do
    render
    byebug
    assert_select
"tr>td", :text => "MyText".to_s, :count => 2
    assert_select
"tr>td", :text => "MyText".to_s, :count => 2
    assert_select
"tr>td", :text => "MyText".to_s, :count => 2
 
end
end
So is it deprecated?  What's it replaced by?  Where can I find documentation? 


I find
no mention of assert_select in http://rspec.info/documentation/3.6/rspec-rails/

I find assert_select
defined in ~/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rails-dom-testing-2.0.3/lib/rails/dom/testing/assertions/selector_assertions.rb .

What am I not understanding?

Frederick Cheung

unread,
Jul 14, 2017, 7:15:04 AM7/14/17
to Ruby on Rails: Talk

On Friday, July 14, 2017 at 9:58:56 AM UTC+1, Ralph Shnelvar wrote:
So is it deprecated?  What's it replaced by?  Where can I find documentation? 


apidock things things are deprecated when they move - it doesn't know it was extracted into the rails-dom-testing gem 


I find
no mention of assert_select in http://rspec.info/documentation/3.6/rspec-rails/


The rails specific assertions aren't part of rspec-rails (you can still use them because rspec-rails wraps the rails testing facilities). ALthough rspec doesn't really care what assertion library you use, I've more commonly seen people use the capybara rspec matches in such cases (expect(rendered).to have_css('tr>td', count: 2, ...)

Fred

Ralph Shnelvar

unread,
Jul 14, 2017, 9:49:48 AM7/14/17
to Ruby on Rails: Talk
So ... where can I find current documentation on assert_select?

Is assert_select an Rspec facility or a wrapper around some other facility I need to learn?

If it isn't apparent, Fred, thank you.

Ralph

Frederick Cheung

unread,
Jul 14, 2017, 1:01:51 PM7/14/17
to Ruby on Rails: Talk
On Friday, July 14, 2017 at 2:49:48 PM UTC+1, Ralph Shnelvar wrote:
> So ... where can I find current documentation on assert_select?
>
> Is assert_select an Rspec facility or a wrapper around some other facility I need to learn?
>

It was extracted from rails into the rails-dom-testing gem, so I would start with https://github.com/rails/rails-dom-testing/blob/master/README.md

Fred
Reply all
Reply to author
Forward
0 new messages