Skip to content

Commit

Permalink
Replace assert_select by rspec expectations
Browse files Browse the repository at this point in the history
Co-authored-by: Saray Cabrera Padrón <scabrerapadron@suse.de>
  • Loading branch information
danidoni and saraycp committed Oct 3, 2022
1 parent 4bbe980 commit b6eab67
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 108 deletions.
14 changes: 5 additions & 9 deletions src/api/spec/controllers/group_controller_spec.rb
Expand Up @@ -21,11 +21,9 @@
it { is_expected.to have_http_status(:success) }

it 'returns with the xml representation of that group' do
assert_select 'group' do
assert_select 'title', group.title
assert_select 'email', group.email
assert_select 'maintainer', userid: group_maintainer
end
expect(response.body).to have_selector('group > title', text: group.title)
expect(response.body).to have_selector('group > email', text: group.email)
expect(response.body).to have_selector("group > maintainer[userid=#{group_maintainer}]")
end
end

Expand All @@ -50,10 +48,8 @@
it { is_expected.to have_http_status(:success) }

it 'returns with the group xml representation' do
assert_select "directory[count=#{groups.count}]" do
groups.each do |group|
assert_select 'entry', name: group.title
end
groups.each do |group|
expect(response.body).to have_selector("directory[count=#{groups.count}] > entry[name=#{group.title}]")
end
end
end
Expand Down
5 changes: 2 additions & 3 deletions src/api/spec/controllers/request_controller_spec.rb
Expand Up @@ -49,9 +49,8 @@
it 'prohibits creation of request', vcr: true do
expect { post :global_command, params: { cmd: :create }, body: xml, format: :xml }.not_to change(BsRequest, :count)
expect(response).to have_http_status(:forbidden)
assert_select 'status[code=lacking_maintainership]' do
assert_select 'summary', text: 'Creating a submit request action with options requires maintainership in source package'
end
expect(response.body).to have_selector('status[code=lacking_maintainership] > summary',
text: 'Creating a submit request action with options requires maintainership in source package')
end
end
end
Expand Down
8 changes: 2 additions & 6 deletions src/api/spec/controllers/staging/backlog_controller_spec.rb
Expand Up @@ -31,9 +31,7 @@
it { expect(response).to have_http_status(:success) }

it 'returns the backlog xml' do
assert_select 'backlog' do
assert_select 'request', 1
end
expect(response.body).to have_selector('backlog > request', count: 1)
end
end

Expand All @@ -55,9 +53,7 @@
it { expect(response).to have_http_status(:not_found) }

it 'responds_with_an_error' do
assert_select 'status' do
assert_select 'summary', text: "Project #{other_project} doesn't have an asociated Staging Workflow"
end
expect(response.body).to have_selector('status > summary', text: "Project #{other_project} doesn't have an asociated Staging Workflow")
end
end
end
Expand Down
Expand Up @@ -39,17 +39,14 @@
it { expect(response).to have_http_status(:success) }

it 'returns the excluded_requests xml' do
assert_select 'excluded_requests', 1 do
assert_select 'request', 2 do
assert_select "[id='#{bs_request.number}']"
assert_select "[id='#{bs_request_2.number}']"
assert_select "[package='#{bs_request.first_target_package}']"
assert_select "[package='#{bs_request_2.first_target_package}']"
assert_select "[description='Request 2']"
assert_select "[description='Request 1']"
assert_select "[description='Request 2']"
end
end
expect(response.body).to have_selector('excluded_requests', count: 1)
expect(response.body).to have_selector('excluded_requests > request', count: 2)
expect(response.body).to have_selector("excluded_requests > request[id='#{bs_request.number}']")
expect(response.body).to have_selector("excluded_requests > request[id='#{bs_request_2.number}']")
expect(response.body).to have_selector("excluded_requests > request[package='#{bs_request.first_target_package}']")
expect(response.body).to have_selector("excluded_requests > request[package='#{bs_request_2.first_target_package}']")
expect(response.body).to have_selector("excluded_requests > request[description='Request 1']")
expect(response.body).to have_selector("excluded_requests > request[description='Request 2']")
end
end

Expand Down
Expand Up @@ -36,9 +36,7 @@
it { expect(response).to have_http_status(:success) }

it 'returns the staged_requests xml' do
assert_select 'staged_requests' do
assert_select 'request', 1
end
expect(response.body).to have_selector('staged_requests > request', count: 1)
end
end

Expand Down Expand Up @@ -87,7 +85,7 @@
it { expect(response).to have_http_status(:failed_dependency) }

it 'responds with an error' do
assert_select 'status', code: 'staging_project_not_in_acceptable_state'
expect(response.body).to have_selector('status[code=staging_project_not_in_acceptable_state]')
end
end

Expand All @@ -101,7 +99,7 @@
it { expect(response).to have_http_status(:success) }
it { expect(staging_project.packages.pluck(:name)).to match_array([target_package.name]) }
it { expect(staging_project.staged_requests).to include(bs_request) }
it { assert_select 'status[code=ok]' }
it { expect(response.body).to have_selector('status[code=ok]') }
end

context 'with delete request', vcr: true do
Expand All @@ -114,7 +112,7 @@
it { expect(response).to have_http_status(:success) }
it { expect(staging_project.packages.pluck(:name)).not_to include(target_package.name) }
it { expect(staging_project.staged_requests).to include(delete_request) }
it { assert_select 'status[code=ok]' }
it { expect(response.body).to have_selector('status[code=ok]') }
end

context 'with an excluded request', vcr: true do
Expand Down Expand Up @@ -168,7 +166,7 @@
it { expect(response).to have_http_status(:success) }
it { expect(staging_project.packages.pluck(:name)).to match_array([target_package.name]) }
it { expect(staging_project.staged_requests).to include(bs_request) }
it { assert_select 'status[code=ok]' }
it { expect(response.body).to have_selector('status[code=ok]') }
end
end

Expand Down Expand Up @@ -249,7 +247,7 @@
it { expect(response).to have_http_status(:success) }
it { expect(staging_project.staged_requests).to include(bs_request) }
it { expect(staging_project.staged_requests).to include(another_bs_request) }
it { assert_select 'status[code=ok]' }
it { expect(response.body).to have_selector('status[code=ok]') }
end
end

Expand Down Expand Up @@ -358,7 +356,7 @@
it { expect(response).to have_http_status(:success) }
it { expect(staging_project.packages.pluck(:name)).to match_array(['new_package']) }
it { expect(staging_project.staged_requests).to include(bs_request) }
it { assert_select 'status[code=ok]' }
it { expect(response.body).to have_selector('status[code=ok]') }
end
end

Expand Down
100 changes: 41 additions & 59 deletions src/api/spec/controllers/staging/staging_projects_controller_spec.rb
Expand Up @@ -110,15 +110,13 @@
it { expect(response.body).not_to include("<staging_project name=\"#{staging_project.name}\" state=") }

it 'returns the staging_project default xml' do
assert_select 'staging_project' do
assert_select 'staged_requests', 0
assert_select 'untracked_requests', 0
assert_select 'obsolete_requests', 0
assert_select 'missing_reviews', 0
assert_select 'broken_packages', 0
assert_select 'checks', 0
assert_select 'history', 0
end
expect(response.body).to have_selector('staging_project > staged_requests', count: 0)
expect(response.body).to have_selector('staging_project > untracked_requests', count: 0)
expect(response.body).to have_selector('staging_project > obsolete_requests', count: 0)
expect(response.body).to have_selector('staging_project > missing_reviews', count: 0)
expect(response.body).to have_selector('staging_project > broken_packages', count: 0)
expect(response.body).to have_selector('staging_project > checks', count: 0)
expect(response.body).to have_selector('staging_project > history', count: 0)
end
end

Expand All @@ -133,21 +131,16 @@
it { expect(response.body).not_to include("<staging_project name=\"#{staging_project.name}\" state=") }

it 'returns the staging_project with requests xml' do
assert_select 'staging_project' do
assert_select 'staged_requests', 1 do
assert_select 'request', 3
end
assert_select 'untracked_requests', 1 do
assert_select 'request', 1
end
assert_select 'obsolete_requests', 1
assert_select 'missing_reviews', 1 do
assert_select 'review', 1
end
assert_select 'broken_packages', 0
assert_select 'checks', 0
assert_select 'history', 0
end
expect(response.body).to have_selector('staging_project > staged_requests', count: 1)
expect(response.body).to have_selector('staging_project > staged_requests > request', count: 3)
expect(response.body).to have_selector('staging_project > untracked_requests', count: 1)
expect(response.body).to have_selector('staging_project > untracked_requests > request', count: 1)
expect(response.body).to have_selector('staging_project > obsolete_requests', count: 1)
expect(response.body).to have_selector('staging_project > missing_reviews', count: 1)
expect(response.body).to have_selector('staging_project > missing_reviews > review', count: 1)
expect(response.body).to have_selector('staging_project > broken_packages', count: 0)
expect(response.body).to have_selector('staging_project > checks', count: 0)
expect(response.body).to have_selector('staging_project > history', count: 0)
end
end

Expand All @@ -162,17 +155,14 @@
it { expect(response.body).to include("<staging_project name=\"#{staging_project.name}\" state=") }

it 'returns the staging_project with status xml' do
assert_select 'staging_project' do
assert_select 'staged_requests', 0
assert_select 'untracked_requests', 0
assert_select 'obsolete_requests', 0
assert_select 'missing_reviews', 0
assert_select 'broken_packages', 1 do
assert_select 'package', 2
end
assert_select 'checks', 1
assert_select 'history', 0
end
expect(response.body).to have_selector('staging_project > staged_requests', count: 0)
expect(response.body).to have_selector('staging_project > untracked_requests', count: 0)
expect(response.body).to have_selector('staging_project > obsolete_requests', count: 0)
expect(response.body).to have_selector('staging_project > missing_reviews', count: 0)
expect(response.body).to have_selector('staging_project > broken_packages', count: 1)
expect(response.body).to have_selector('staging_project > broken_packages > package', count: 2)
expect(response.body).to have_selector('staging_project > checks', count: 1)
expect(response.body).to have_selector('staging_project > history', count: 0)
end
end

Expand All @@ -187,14 +177,12 @@
it { expect(response.body).not_to include("<staging_project name=\"#{staging_project.name}\" state=") }

it 'returns the staging_project with history xml' do
assert_select 'staging_project' do
assert_select 'staged_requests', 0
assert_select 'untracked_requests', 0
assert_select 'obsolete_requests', 0
assert_select 'missing_reviews', 0
assert_select 'broken_packages', 0
assert_select 'history', 1
end
expect(response.body).to have_selector('staging_project > staged_requests', count: 0)
expect(response.body).to have_selector('staging_project > untracked_requests', count: 0)
expect(response.body).to have_selector('staging_project > obsolete_requests', count: 0)
expect(response.body).to have_selector('staging_project > missing_reviews', count: 0)
expect(response.body).to have_selector('staging_project > broken_packages', count: 0)
expect(response.body).to have_selector('staging_project > history', count: 1)
end
end

Expand All @@ -209,22 +197,16 @@
it { expect(response.body).to include("<staging_project name=\"#{staging_project.name}\" state=") }

it 'returns the staging_project with requests, status and history xml' do
assert_select 'staging_project' do
assert_select 'staged_requests', 1 do
assert_select 'request', 3
end
assert_select 'untracked_requests', 1 do
assert_select 'request', 1
end
assert_select 'obsolete_requests', 1
assert_select 'missing_reviews', 1 do
assert_select 'review', 1
end
assert_select 'broken_packages', 1 do
assert_select 'package', 2
end
assert_select 'history', 1
end
expect(response.body).to have_selector('staging_project > staged_requests', count: 1)
expect(response.body).to have_selector('staging_project > staged_requests > request', count: 3)
expect(response.body).to have_selector('staging_project > untracked_requests', count: 1)
expect(response.body).to have_selector('staging_project > untracked_requests > request', count: 1)
expect(response.body).to have_selector('staging_project > obsolete_requests', count: 1)
expect(response.body).to have_selector('staging_project > missing_reviews', count: 1)
expect(response.body).to have_selector('staging_project > missing_reviews > review', count: 1)
expect(response.body).to have_selector('staging_project > broken_packages', count: 1)
expect(response.body).to have_selector('staging_project > broken_packages > package', count: 2)
expect(response.body).to have_selector('staging_project > history', count: 1)
end
end
end
Expand Down
Expand Up @@ -39,7 +39,7 @@
end

it 'hides the project' do
assert_response :not_found
expect(response).to have_http_status(:not_found)
end
end

Expand Down
10 changes: 3 additions & 7 deletions src/api/spec/controllers/status_messages_controller_spec.rb
Expand Up @@ -17,9 +17,7 @@
it { is_expected.to have_http_status(:success) }

it 'returns the requested status message' do
assert_select 'status_message' do
assert_select 'message', status_message.message
end
expect(response.body).to have_selector('status_message > message', text: status_message.message)
end
end

Expand All @@ -31,10 +29,8 @@
it { is_expected.to have_http_status(:success) }

it 'returns all status messages' do
assert_select 'status_messages[count=3]' do
status_messages.each do |status_message|
assert_select 'message', status_message.message
end
status_messages.each do |status_message|
expect(response.body).to have_selector('status_messages[count=3] > status_message > message', text: status_message.message)
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions src/api/spec/controllers/worker/status_controller_spec.rb
Expand Up @@ -10,18 +10,18 @@
end

describe 'GET /index' do
let(:response) { file_fixture('worker_status_response.xml') }
let(:worker_status_response) { file_fixture('worker_status_response.xml') }

before do
stub_request(:get, CONFIG['source_url'] + '/build/_workerstatus').and_return(body: response)
stub_request(:get, CONFIG['source_url'] + '/build/_workerstatus').and_return(body: worker_status_response)
end

subject! { get :index, params: { format: :xml } }

it { is_expected.to have_http_status(:success) }

it 'finds 2 workers' do
assert_select 'workerstatus[clients=2]'
expect(response.body).to have_selector('workerstatus[clients=2]')
end
end
end

0 comments on commit b6eab67

Please sign in to comment.