Skip to content

Commit 1607149

Browse files
author
David Rodríguez
committed
Fix failing scenarios in jruby
I'm not sure why but somehow some assertions don't seem to wait for the content to appear in jruby. Migrating this tests to use a javascript driver fixes it. Furthermore, I think this is a good change (except for performance) because this tests are actually supposed test js behaviour. The only reason they were passing with a non-js driver is that they manually simulate the js behaviour. See the "When I submit the batch action form" step for an example. It's not testing the real behavior of the user, so if any regressions are introduced where that stuff actually happens (batch_actions.js.coffee), they won't be catched by the test. Regarding the actual migration of the tests, it includes a couple of changes to avoid using :contains or :first that are not valid css selectors and are only working "by chance" (see [1], last comment) and a rewrite of the previously mentioned step at a higher level to actually trigger the js that is being tested. [1]: teampoltergeist/poltergeist#323
1 parent 73d182d commit 1607149

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

features/index/batch_actions.feature

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Feature: Batch Actions
22

3+
@javascript
34
Scenario: Use default (destroy) batch action
45
Given 10 posts exist
56
And an index configuration of:
@@ -16,7 +17,7 @@ Feature: Batch Actions
1617
And I follow "Batch Actions"
1718
Then I should see the batch action :destroy "Delete Selected"
1819

19-
Given I submit the batch action form with "destroy"
20+
Given I click "Delete Selected" and accept confirmation
2021
Then I should see a flash with "Successfully destroyed 2 posts"
2122
And I should see 8 posts in the table
2223

@@ -37,6 +38,7 @@ Feature: Batch Actions
3738
Then I should see a flash with "Successfully destroyed 2 posts"
3839
And I should see 3 posts in the table
3940

41+
@javascript
4042
Scenario: Use default (destroy) batch action on a nested resource
4143
Given I am logged in
4244
And 5 posts written by "John Doe" exist
@@ -58,7 +60,7 @@ Feature: Batch Actions
5860
And I follow "Batch Actions"
5961
Then I should see the batch action :destroy "Delete Selected"
6062

61-
Given I submit the batch action form with "destroy"
63+
Given I click "Delete Selected" and accept confirmation
6264
Then I should see a flash with "Successfully destroyed 2 posts"
6365
And I should see 3 posts in the table
6466

features/step_definitions/batch_action_steps.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
end
88

99
Then /^I (should|should not) see the batch action :([^\s]*) "([^"]*)"$/ do |maybe, sym, title|
10-
selector = ".batch_actions_selector a.batch_action:contains('#{title}')"
10+
selector = ".batch_actions_selector a.batch_action"
1111
selector << "[href='#'][data-action='#{sym}']" if maybe == 'should'
1212

1313
verb = maybe == 'should' ? :to : :to_not
14-
expect(page).send verb, have_css(selector)
14+
expect(page).send verb, have_css(selector, text: title)
1515
end
1616

1717
Then /^the (\d+)(?:st|nd|rd|th) batch action should be "([^"]*)"$/ do |index, title|
@@ -57,6 +57,15 @@
5757
page.driver.submit form['method'], form['action'], params
5858
end
5959

60+
When /^I click "(.*?)" and accept confirmation$/ do |link|
61+
# Use this implementation instead if poltergeist ever implements it
62+
# page.driver.accept_modal(:confirm) { click_link(link) }
63+
64+
click_link(link)
65+
expect(page).to have_content("Are you sure you want to delete these posts?")
66+
click_button("OK")
67+
end
68+
6069
Then /^I should not see checkboxes in the table$/ do
6170
expect(page).to_not have_css '.paginated_collection table input[type=checkbox]'
6271
end

features/step_definitions/table_steps.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Then /^I should see (\d+) ([\w]*) in the table$/ do |count, resource_type|
2-
expect(all("table.index_table tr > td:first").count).to eq count.to_i
2+
expect(page).to \
3+
have_css("table.index_table tr > td:first-child", count: count.to_i)
34
end
45

56
# TODO: simplify this, if possible?

0 commit comments

Comments
 (0)