Update assert_select for Nokogiri compatibility

assert_select has been moved into the rails-dom-testing gem and is now
based on Nokogiri.

* Remove assert_tag and assert_xml_select
* Quote CSS attribute selector values
* Use decoded versions of HTML in assert_select. Nokogiri decodes
  elements prior to matching.
* Add a test helper for entities such as ` ` for which it's
  difficult or confusing to include the decoded version directly in the
  assertion.
* Assert directly on Atom feeds' XML namespace because it isn't
  selectable as an attribute
This commit is contained in:
Dan Rice 2015-08-09 17:43:40 -04:00
parent d7d86446c0
commit 689db4c9c3
9 changed files with 66 additions and 64 deletions

View file

@ -6,11 +6,12 @@ class ProjectXmlApiTest < ActionDispatch::IntegrationTest
def test_retrieve_project
authenticated_get_xml "/projects/1.xml", users(:admin_user).login, 'abracadabra', {}
assert_tag :tag => "project"
assert_tag :tag => "project", :child => {:tag => "not_done" }
assert_tag :tag => "project", :child => {:tag => "deferred" }
assert_tag :tag => "project", :child => {:tag => "pending" }
assert_tag :tag => "project", :child => {:tag => "done" }
assert_select 'project' do
assert_select 'not_done'
assert_select 'deferred'
assert_select 'pending'
assert_select 'done'
end
assert_response 200
end

View file

@ -24,12 +24,14 @@ class TodoXmlApiTest < ActionDispatch::IntegrationTest
def test_get_tickler_returns_all_deferred_and_pending_todos
number = @user.todos.deferred.count + @user.todos.pending.count
authenticated_get_xml "/tickler.xml", @user.login, @password, {}
assert_tag :tag => "todos", :children => { :count => number }
assert_select 'todos' do
assert_select 'todo', count: number
end
end
def test_get_tickler_omits_user_id
authenticated_get_xml "/tickler.xml", @user.login, @password, {}
assert_no_tag :tag => "user_id"
assert_select 'user_id', false
end
def test_get_index_with_only_active_todos
@ -245,7 +247,7 @@ class TodoXmlApiTest < ActionDispatch::IntegrationTest
<project_id type='integer'>-11</project_id>
</todo>"
assert_response 409
assert_xml_select 'errors' do
assert_select 'errors' do
assert_select 'error', 2
end
end
@ -261,4 +263,4 @@ class TodoXmlApiTest < ActionDispatch::IntegrationTest
authenticated_post_xml "/todos.xml", user, password, postdata
end
end
end

View file

@ -69,16 +69,17 @@ class UsersXmlApiTest < ActionDispatch::IntegrationTest
def test_get_users_as_xml
get '/users.xml', {}, basic_auth_headers()
assert_response :success
assert_tag :tag => "users",
:children => { :count => 4, :only => { :tag => "user" } }
assert_no_tag :tag => "password"
assert_select 'users' do
assert_select 'user', count: 4
end
assert_select 'password', false
end
def test_get_user_as_xml
get "/users/#{users(:other_user).id}.xml", {}, basic_auth_headers()
assert_response :success
assert_tag :tag => "user"
assert_no_tag :tag => "password"
assert_select 'user'
assert_select 'password', false
end
private