Commit 81eae5de89d13e6079ee5a9d975216d1a460d8d0
1 parent
3f94e14d
Exists in
master
and in
4 other branches
Capybara tests with first-child/last-child randomly fails so replaced with alternative method
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Showing
1 changed file
with
18 additions
and
10 deletions
Show diff stats
spec/features/issues_spec.rb
| @@ -107,15 +107,15 @@ describe "Issues" do | @@ -107,15 +107,15 @@ describe "Issues" do | ||
| 107 | it 'sorts by newest' do | 107 | it 'sorts by newest' do |
| 108 | visit project_issues_path(project, sort: 'newest') | 108 | visit project_issues_path(project, sort: 'newest') |
| 109 | 109 | ||
| 110 | - page.should have_selector("ul.issues-list li:first-child", text: 'foo') | ||
| 111 | - page.should have_selector("ul.issues-list li:last-child", text: 'baz') | 110 | + first_issue.should include("foo") |
| 111 | + last_issue.should include("baz") | ||
| 112 | end | 112 | end |
| 113 | 113 | ||
| 114 | it 'sorts by oldest' do | 114 | it 'sorts by oldest' do |
| 115 | visit project_issues_path(project, sort: 'oldest') | 115 | visit project_issues_path(project, sort: 'oldest') |
| 116 | 116 | ||
| 117 | - page.should have_selector("ul.issues-list li:first-child", text: 'baz') | ||
| 118 | - page.should have_selector("ul.issues-list li:last-child", text: 'foo') | 117 | + first_issue.should include("baz") |
| 118 | + last_issue.should include("foo") | ||
| 119 | end | 119 | end |
| 120 | 120 | ||
| 121 | it 'sorts by most recently updated' do | 121 | it 'sorts by most recently updated' do |
| @@ -123,7 +123,7 @@ describe "Issues" do | @@ -123,7 +123,7 @@ describe "Issues" do | ||
| 123 | baz.save | 123 | baz.save |
| 124 | visit project_issues_path(project, sort: 'recently_updated') | 124 | visit project_issues_path(project, sort: 'recently_updated') |
| 125 | 125 | ||
| 126 | - page.should have_selector("ul.issues-list li:first-child", text: 'baz') | 126 | + first_issue.should include("baz") |
| 127 | end | 127 | end |
| 128 | 128 | ||
| 129 | it 'sorts by least recently updated' do | 129 | it 'sorts by least recently updated' do |
| @@ -131,7 +131,7 @@ describe "Issues" do | @@ -131,7 +131,7 @@ describe "Issues" do | ||
| 131 | baz.save | 131 | baz.save |
| 132 | visit project_issues_path(project, sort: 'last_updated') | 132 | visit project_issues_path(project, sort: 'last_updated') |
| 133 | 133 | ||
| 134 | - page.should have_selector("ul.issues-list li:first-child", text: 'baz') | 134 | + first_issue.should include("baz") |
| 135 | end | 135 | end |
| 136 | 136 | ||
| 137 | describe 'sorting by milestone' do | 137 | describe 'sorting by milestone' do |
| @@ -145,13 +145,13 @@ describe "Issues" do | @@ -145,13 +145,13 @@ describe "Issues" do | ||
| 145 | it 'sorts by recently due milestone' do | 145 | it 'sorts by recently due milestone' do |
| 146 | visit project_issues_path(project, sort: 'milestone_due_soon') | 146 | visit project_issues_path(project, sort: 'milestone_due_soon') |
| 147 | 147 | ||
| 148 | - page.should have_selector("ul.issues-list li:first-child", text: 'foo') | 148 | + first_issue.should include("foo") |
| 149 | end | 149 | end |
| 150 | 150 | ||
| 151 | it 'sorts by least recently due milestone' do | 151 | it 'sorts by least recently due milestone' do |
| 152 | visit project_issues_path(project, sort: 'milestone_due_later') | 152 | visit project_issues_path(project, sort: 'milestone_due_later') |
| 153 | 153 | ||
| 154 | - page.should have_selector("ul.issues-list li:first-child", text: 'bar') | 154 | + first_issue.should include("bar") |
| 155 | end | 155 | end |
| 156 | end | 156 | end |
| 157 | 157 | ||
| @@ -168,10 +168,18 @@ describe "Issues" do | @@ -168,10 +168,18 @@ describe "Issues" do | ||
| 168 | it 'sorts with a filter applied' do | 168 | it 'sorts with a filter applied' do |
| 169 | visit project_issues_path(project, sort: 'oldest', assignee_id: user2.id) | 169 | visit project_issues_path(project, sort: 'oldest', assignee_id: user2.id) |
| 170 | 170 | ||
| 171 | - page.should have_selector("ul.issues-list li:first-child", text: 'bar') | ||
| 172 | - page.should have_selector("ul.issues-list li:last-child", text: 'foo') | 171 | + first_issue.should include("bar") |
| 172 | + last_issue.should include("foo") | ||
| 173 | page.should_not have_content 'baz' | 173 | page.should_not have_content 'baz' |
| 174 | end | 174 | end |
| 175 | end | 175 | end |
| 176 | end | 176 | end |
| 177 | + | ||
| 178 | + def first_issue | ||
| 179 | + all("ul.issues-list li").first.text | ||
| 180 | + end | ||
| 181 | + | ||
| 182 | + def last_issue | ||
| 183 | + all("ul.issues-list li").last.text | ||
| 184 | + end | ||
| 177 | end | 185 | end |