diff --git a/spec/support/common_actions/comments.rb b/spec/support/common_actions/comments.rb index 370e16fd9..1f600470b 100644 --- a/spec/support/common_actions/comments.rb +++ b/spec/support/common_actions/comments.rb @@ -18,8 +18,4 @@ module Comments end expect(page).to have_content "It will be done next week." end - - def avatar(name) - "img.initialjs-avatar[data-name='#{name}']" - end end diff --git a/spec/support/matchers/have_avatar.rb b/spec/support/matchers/have_avatar.rb new file mode 100644 index 000000000..d68757ceb --- /dev/null +++ b/spec/support/matchers/have_avatar.rb @@ -0,0 +1,9 @@ +RSpec::Matchers.define :have_avatar do |name, **options| + match do + has_css?("img.initialjs-avatar[data-name='#{name}'][src^='data:image/svg']", **options) + end + + failure_message do + "expected to find avatar with name #{name} but there were no matches." + end +end diff --git a/spec/system/account_spec.rb b/spec/system/account_spec.rb index 6d23e854b..d98d2f7ff 100644 --- a/spec/system/account_spec.rb +++ b/spec/system/account_spec.rb @@ -15,7 +15,7 @@ describe "Account" do expect(page).to have_current_path(account_path, ignore_query: true) expect(page).to have_css "input[value='Manuela Colau']" - expect(page).to have_css avatar("Manuela Colau"), count: 1 + expect(page).to have_avatar "Manuela Colau", count: 1 end scenario "Show organization" do @@ -26,7 +26,7 @@ describe "Account" do expect(page).to have_css "input[value='Manuela Corp']" expect(page).not_to have_css "input[value='Manuela Colau']" - expect(page).to have_css avatar("Manuela Corp"), count: 1 + expect(page).to have_avatar "Manuela Corp", count: 1 end scenario "Edit" do diff --git a/spec/system/debates_spec.rb b/spec/system/debates_spec.rb index fa70d949f..ba83f2a1f 100644 --- a/spec/system/debates_spec.rb +++ b/spec/system/debates_spec.rb @@ -72,15 +72,15 @@ describe "Debates" do end scenario "Show" do - debate = create(:debate) + debate = create(:debate, author: create(:user, username: "Charles Dickens")) visit debate_path(debate) expect(page).to have_content debate.title expect(page).to have_content "Debate description" - expect(page).to have_content debate.author.name + expect(page).to have_content "Charles Dickens" expect(page).to have_content I18n.l(debate.created_at.to_date) - expect(page).to have_css avatar(debate.author.name) + expect(page).to have_avatar "Charles Dickens" expect(page.html).to include "