diff --git a/.simplecov b/.simplecov index 48819cfc0..a8a127f73 100644 --- a/.simplecov +++ b/.simplecov @@ -1,9 +1,11 @@ -SimpleCov.start "rails" do - add_filter "/spec/" - add_filter "/dashboards/" - add_filter "/app/controllers/admin/" - add_filter "/app/controllers/internal/" - add_filter "/app/black_box/" - add_filter "/app/fields/" - add_filter "/app/views/admin/" +if ENV["COVERAGE"] + SimpleCov.start "rails" do + add_filter "/spec/" + add_filter "/dashboards/" + add_filter "/app/controllers/admin/" + add_filter "/app/controllers/internal/" + add_filter "/app/black_box/" + add_filter "/app/fields/" + add_filter "/app/views/admin/" + end end diff --git a/.travis.yml b/.travis.yml index 9a5516009..bdebecb2b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,6 +15,7 @@ env: - RAILS_ENV=test - CC_TEST_REPORTER_ID=f39e060a8b1a558ebd8aff75d5b9760bf1ae98f3f85d628ae28814f3c66438cd - DATABASE_URL=postgres://postgres@localhost/ + - COVERAGE=true branches: only: - master diff --git a/Gemfile b/Gemfile index 4a04a27df..6fb9e35db 100644 --- a/Gemfile +++ b/Gemfile @@ -139,7 +139,7 @@ end group :test do gem "approvals", "~> 0.0" # A library to make it easier to do golden-master style testing in Ruby - gem "factory_bot_rails", "~> 5.0" # factory_bot is a fixtures replacement with a straightforward definition syntax, support for multiple build strategies + gem "factory_bot_rails", "~> 4.11" # factory_bot is a fixtures replacement with a straightforward definition syntax, support for multiple build strategies gem "launchy", "~> 2.4" # Launchy is helper class for launching cross-platform applications in a fire and forget manner. gem "pundit-matchers", "~> 1.6" # A set of RSpec matchers for testing Pundit authorisation policies gem "rspec-retry", "~> 0.6" # retry intermittently failing rspec examples diff --git a/Gemfile.lock b/Gemfile.lock index 6a8116159..918abf1f8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -308,11 +308,11 @@ GEM eventmachine (1.2.5) excon (0.64.0) execjs (2.7.0) - factory_bot (5.0.2) - activesupport (>= 4.2.0) - factory_bot_rails (5.0.2) - factory_bot (~> 5.0.2) - railties (>= 4.2.0) + factory_bot (4.11.1) + activesupport (>= 3.0.0) + factory_bot_rails (4.11.1) + factory_bot (~> 4.11.1) + railties (>= 3.0.0) faker (1.9.3) i18n (>= 0.7) faraday (0.15.4) @@ -869,7 +869,7 @@ DEPENDENCIES emoji_regex (~> 2.0) envied (~> 0.9) erb_lint (~> 0.0) - factory_bot_rails (~> 5.0) + factory_bot_rails (~> 4.11) faker (~> 1.9) fastly (~> 1.15) fastly-rails (~> 0.8) diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index ea2b38eef..c75e258dc 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -12,6 +12,7 @@ require "pundit/matchers" require "pundit/rspec" require "webmock/rspec" require "test_prof/recipes/rspec/before_all" +require "test_prof/recipes/rspec/let_it_be" # Requires supporting ruby files with custom matchers and macros, etc, in # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are diff --git a/spec/system/articles/user_edits_an_article_spec.rb b/spec/system/articles/user_edits_an_article_spec.rb index 1a312efe7..644a1e26a 100644 --- a/spec/system/articles/user_edits_an_article_spec.rb +++ b/spec/system/articles/user_edits_an_article_spec.rb @@ -1,36 +1,36 @@ require "rails_helper" -RSpec.describe "Editing with an editor", type: :system do - let!(:user) { create(:user) } - let!(:template) { file_fixture("article_published.txt").read } - let(:article) { create(:article, user: user, body_markdown: template) } +RSpec.describe "Editing with an editor", type: :system, js: true do + let_it_be(:template) { file_fixture("article_published.txt").read } + let_it_be(:user) { create(:user) } + let_it_be(:article, reload: true) { create(:article, user: user, body_markdown: template) } before do sign_in user end - it "user clicks the edit button", js: true, retry: 3 do + it "user clicks the edit button" do link = "/#{user.username}/#{article.slug}" visit link find("#action-space").click expect(page).to have_current_path(link + "/edit") end - it "user previews their changes", js: true, retry: 3 do + it "user previews their changes" do visit "/#{user.username}/#{article.slug}/edit" fill_in "article_body_markdown", with: template.gsub("Suspendisse", "Yooo") click_button("PREVIEW") expect(page).to have_text("Yooo") end - it "user updates their post", js: true, retry: 3 do + it "user updates their post" do visit "/#{user.username}/#{article.slug}/edit" fill_in "article_body_markdown", with: template.gsub("Suspendisse", "Yooo") click_button("SAVE CHANGES") expect(page).to have_text("Yooo") end - it "user unpublishes their post", js: true, retry: 3 do + it "user unpublishes their post" do visit "/#{user.username}/#{article.slug}/edit" fill_in "article_body_markdown", with: template.gsub("true", "false") click_button("SAVE CHANGES") diff --git a/spec/system/articles/user_visits_an_article_spec.rb b/spec/system/articles/user_visits_an_article_spec.rb index 8bbb78f67..9278c6e76 100644 --- a/spec/system/articles/user_visits_an_article_spec.rb +++ b/spec/system/articles/user_visits_an_article_spec.rb @@ -1,13 +1,9 @@ require "rails_helper" RSpec.describe "Views an article", type: :system do - let(:user) { create(:user) } - let(:dir) { "../../support/fixtures/sample_article.txt" } - let(:template) { File.read(File.join(File.dirname(__FILE__), dir)) } - let!(:article) do - create(:article, user_id: user.id, body_markdown: template.gsub("false", "true"), body_html: "") - end - let!(:timestamp) { "2019-03-04T10:00:00Z" } + let_it_be(:user) { create(:user) } + let_it_be(:article, reload: true) { create(:article, user: user) } + let(:timestamp) { "2019-03-04T10:00:00Z" } before do sign_in user @@ -18,7 +14,7 @@ RSpec.describe "Views an article", type: :system do expect(page).to have_content(article.title) end - it "shows comments", js: true, retry: 3 do + it "shows comments", js: true do create_list(:comment, 3, commentable: article) visit "/#{user.username}/#{article.slug}" expect(page).to have_selector(".single-comment-node", visible: true, count: 3)