spec: bit less code duplication

This commit is contained in:
Georg Gadinger 2020-04-30 19:15:32 +02:00
parent fcdb640b9a
commit 6a7e8a3023
4 changed files with 16 additions and 21 deletions

View File

@ -3,13 +3,7 @@
require "rails_helper"
describe Ajax::AnswerController, type: :controller do
shared_examples "returns the expected response" do
it "returns the expected response" do
expect(JSON.parse(subject.body)).to match(expected_response)
end
end
describe Ajax::AnswerController, :ajax_controller, type: :controller do
let(:user) { FactoryBot.create(:user) }
let(:question) { FactoryBot.create(:question, user: FactoryBot.build(:user, privacy_allow_stranger_answers: asker_allows_strangers)) }
let(:asker_allows_strangers) { true }

View File

@ -3,13 +3,7 @@
require "rails_helper"
describe Ajax::CommentController, type: :controller do
shared_examples "returns the expected response" do
it "returns the expected response" do
expect(JSON.parse(subject.body)).to match(expected_response)
end
end
describe Ajax::CommentController, :ajax_controller, type: :controller do
let(:user) { FactoryBot.create(:user) }
let(:answer) { FactoryBot.create(:answer, user: FactoryBot.create(:user)) }

View File

@ -3,13 +3,7 @@
require "rails_helper"
describe Ajax::SmileController, type: :controller do
shared_examples "returns the expected response" do
it "returns the expected response" do
expect(JSON.parse(subject.body)).to match(expected_response)
end
end
describe Ajax::SmileController, :ajax_controller, type: :controller do
let(:user) { FactoryBot.create(:user) }
describe "#create" do

View File

@ -0,0 +1,13 @@
# frozen_string_literal: true
RSpec.shared_context "AjaxController context" do
shared_examples "returns the expected response" do
it "returns the expected response" do
expect(JSON.parse(subject.body)).to match(expected_response)
end
end
end
RSpec.configure do |c|
c.include_context "AjaxController context", ajax_controller: true
end