Skip to content

Commit 2db96a9

Browse files
committed
Simplify spec with let
1 parent fb478b0 commit 2db96a9

1 file changed

Lines changed: 13 additions & 20 deletions

File tree

spec/features/comment_spec.rb

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
feature 'Comment' do
44
let(:user) { create :user }
5+
let(:project) { create(:idea, originator: user) }
6+
let(:project_with_comments) { create(:idea, :with_comments, originator: user) }
7+
let(:comment_text) { Faker::Lorem.sentence }
58

69
before :each do
710
sign_in user
811
end
912

1013
scenario 'markdown preview', :js do
11-
project = create(:invention, originator: user, users: [user])
12-
1314
visit project_path(:all, project)
1415
fill_in 'comment_text', with: '_italic_ **bold** :smile: @user'
1516
click_on 'Preview'
@@ -21,10 +22,8 @@
2122
end
2223

2324
scenario 'create', :js do
24-
project = create(:idea, originator: user)
25-
comment_text = Faker::Lorem.sentence
26-
2725
visit project_path(nil, project)
26+
2827
within('#comments_form_section') do
2928
fill_in 'comment_text', with: comment_text
3029
end
@@ -39,33 +38,27 @@
3938
end
4039

4140
scenario 'reply to a comment', :js do
42-
project = create(:idea, :with_comments, originator: user)
43-
reply_text = 'You are wrong on the internet!'
44-
first_comment = project.comments.first
41+
visit project_path(nil, project_with_comments)
4542

46-
visit project_path(nil, project)
47-
48-
within("li#comment_#{first_comment.id}") do
43+
within("#comment_#{project_with_comments.comments.first.id}") do
4944
click_on 'Reply'
5045
end
5146

52-
within("#replyCommentcomment_#{first_comment.id}") do
53-
fill_in 'comment_text', with: reply_text
47+
within("#replyCommentcomment_#{project_with_comments.comments.first.id}") do
48+
fill_in 'comment_text', with: 'You are wrong on the internet!'
5449
end
5550

56-
within("#replyCommentcomment_#{first_comment.id}") do
51+
within("#replyCommentcomment_#{project_with_comments.comments.first.id}") do
5752
click_on 'Create Comment'
5853
end
5954

60-
within("#comment_#{first_comment.id}") do
61-
expect(page).to have_text reply_text
55+
within("#comment_#{project_with_comments.comments.first.id}") do
56+
expect(page).to have_text 'You are wrong on the internet!'
6257
end
6358
end
6459

6560
scenario 'update', :js do
66-
project = create(:idea, originator: user)
6761
comment = create(:comment, commenter: user, commentable: project)
68-
update_text = Faker::Lorem.sentence
6962

7063
visit project_path(nil, project)
7164

@@ -74,12 +67,12 @@
7467
end
7568

7669
within("#editCommentcomment_#{comment.id}") do
77-
fill_in 'comment_text', with: update_text
70+
fill_in 'comment_text', with: comment_text
7871
click_on 'Update Comment'
7972
end
8073

8174
within("li#comment_#{comment.id}") do
82-
expect(page).to have_text update_text
75+
expect(page).to have_text comment_text
8376
end
8477
end
8578
end

0 commit comments

Comments
 (0)