Skip to content

Commit 425cccb

Browse files
fix specs
1 parent ec01e8f commit 425cccb

File tree

3 files changed

+12
-142
lines changed

3 files changed

+12
-142
lines changed

spec/rails_helper.rb

Lines changed: 5 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,27 @@
11
# frozen_string_literal: true
22

3-
# This file is copied to spec/ when you run 'rails generate rspec:install'
43
require "spec_helper"
54
ENV["RAILS_ENV"] ||= "test"
65
require_relative "../config/environment"
7-
# Prevent database truncation if the environment is production
6+
87
abort("The Rails environment is running in production mode!") if Rails.env.production?
9-
# Uncomment the line below in case you have `--require rails_helper` in the `.rspec` file
10-
# that will avoid rails generators crashing because migrations haven't been run yet
11-
# return unless Rails.env.test?
12-
require "rspec/rails"
13-
# Add additional requires below this line. Rails is not loaded until this point!
148

15-
# Requires supporting ruby files with custom matchers and macros, etc, in
16-
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
17-
# run as spec files by default. This means that files in spec/support that end
18-
# in _spec.rb will both be required and run as specs, causing the specs to be
19-
# run twice. It is recommended that you do not name files matching this glob to
20-
# end with _spec.rb. You can configure this pattern with the --pattern
21-
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
22-
#
23-
# The following line is provided for convenience purposes. It has the downside
24-
# of increasing the boot-up time by auto-requiring all files in the support
25-
# directory. Alternatively, in the individual `*_spec.rb` files, manually
26-
# require only the support files necessary.
27-
#
28-
# Rails.root.glob('spec/support/**/*.rb').sort_by(&:to_s).each { |f| require f }
9+
require "rspec/rails"
2910

30-
# Checks for pending migrations and applies them before tests are run.
31-
# If you are not using ActiveRecord, you can remove these lines.
3211
begin
33-
# TODO: add this back to make specs work with db
34-
# ActiveRecord::Migration.maintain_test_schema!
12+
ActiveRecord::Migration.maintain_test_schema!
3513
rescue ActiveRecord::PendingMigrationError => e
3614
abort(e.to_s.strip)
3715
end
16+
3817
RSpec.configure do |config|
39-
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
4018
config.fixture_paths = [
4119
Rails.root.join("spec/fixtures"),
4220
]
4321

44-
# If you're not using ActiveRecord, or you'd prefer not to run each of your
45-
# examples within a transaction, remove the following line or assign false
46-
# instead of true.
47-
# TODO: add this back to make specs work with db
48-
# config.use_transactional_fixtures = true
49-
50-
# You can uncomment this line to turn off ActiveRecord support entirely.
51-
# config.use_active_record = false
22+
config.use_transactional_fixtures = true
5223

53-
# RSpec Rails can automatically mix in different behaviours to your tests
54-
# based on their file location, for example enabling you to call `get` and
55-
# `post` in specs under `spec/controllers`.
56-
#
57-
# You can disable this behaviour by removing the line below, and instead
58-
# explicitly tag your specs with their type, e.g.:
59-
#
60-
# RSpec.describe UsersController, type: :controller do
61-
# # ...
62-
# end
63-
#
64-
# The different available types are documented in the features, such as in
65-
# https://rspec.info/features/7-0/rspec-rails
6624
config.infer_spec_type_from_file_location!
6725

68-
# Filter lines from Rails gems in backtraces.
6926
config.filter_rails_from_backtrace!
70-
# arbitrary gems may also be filtered via:
71-
# config.filter_gems_from_backtrace("gem name")
7227
end

spec/requests/heartbeat_controller_spec.rb

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,19 @@
44

55
RSpec.describe("HeartbeatControllers", type: :request) do
66
describe "GET /index" do
7-
before do
8-
get "/heartbeat"
9-
end
10-
117
it "returns a 200 status code" do
8+
get "/heartbeat"
129
expect(response).to(have_http_status(200))
1310
end
1411

1512
it "returns json" do
16-
expect(response.content_type).to(eq("application/json"))
13+
get "/heartbeat"
14+
expect(response.content_type).to(eq("application/json; charset=utf-8"))
1715
end
1816

1917
it "retrurns the expected data" do
20-
expect(JSON.parse(response.body)).to(eq({ message: "healthy" }))
18+
get "/heartbeat"
19+
expect(JSON.parse(response.body, symbolize_names: true)).to(eq({ healthy: true }))
2120
end
22-
# get "/heartbeat"
23-
24-
# expect(response).to have_http_status(200)
25-
# expect(response.content_type).to eq("application/json")
26-
# expect(JSON.parse(response.body)).to eq({message: "healthy"})
2721
end
2822
end

spec/spec_helper.rb

Lines changed: 2 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,15 @@
11
# frozen_string_literal: true
22

3-
# This file was generated by the `rails generate rspec:install` command. Conventionally, all
4-
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
5-
# The generated `.rspec` file contains `--require spec_helper` which will cause
6-
# this file to always be loaded, without a need to explicitly require it in any
7-
# files.
8-
#
9-
# Given that it is always loaded, you are encouraged to keep this file as
10-
# light-weight as possible. Requiring heavyweight dependencies from this file
11-
# will add to the boot time of your test suite on EVERY test run, even for an
12-
# individual file that may not need all of that loaded. Instead, consider making
13-
# a separate helper file that requires the additional dependencies and performs
14-
# the additional setup, and require it from the spec files that actually need
15-
# it.
16-
#
17-
# See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
183
RSpec.configure do |config|
19-
# rspec-expectations config goes here. You can use an alternate
20-
# assertion/expectation library such as wrong or the stdlib/minitest
21-
# assertions if you prefer.
4+
ENV["SKIP_TEST_DATABASE_TRUNCATE"] = "true"
5+
226
config.expect_with(:rspec) do |expectations|
23-
# This option will default to `true` in RSpec 4. It makes the `description`
24-
# and `failure_message` of custom matchers include text for helper methods
25-
# defined using `chain`, e.g.:
26-
# be_bigger_than(2).and_smaller_than(4).description
27-
# # => "be bigger than 2 and smaller than 4"
28-
# ...rather than:
29-
# # => "be bigger than 2"
307
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
318
end
329

33-
# rspec-mocks config goes here. You can use an alternate test double
34-
# library (such as bogus or mocha) by changing the `mock_with` option here.
3510
config.mock_with(:rspec) do |mocks|
36-
# Prevents you from mocking or stubbing a method that does not exist on
37-
# a real object. This is generally recommended, and will default to
38-
# `true` in RSpec 4.
3911
mocks.verify_partial_doubles = true
4012
end
4113

42-
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
43-
# have no way to turn it off -- the option exists only for backwards
44-
# compatibility in RSpec 3). It causes shared context metadata to be
45-
# inherited by the metadata hash of host groups and examples, rather than
46-
# triggering implicit auto-inclusion in groups with matching metadata.
4714
config.shared_context_metadata_behavior = :apply_to_host_groups
48-
49-
# The settings below are suggested to provide a good initial experience
50-
# with RSpec, but feel free to customize to your heart's content.
51-
# # This allows you to limit a spec run to individual examples or groups
52-
# # you care about by tagging them with `:focus` metadata. When nothing
53-
# # is tagged with `:focus`, all examples get run. RSpec also provides
54-
# # aliases for `it`, `describe`, and `context` that include `:focus`
55-
# # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
56-
# config.filter_run_when_matching :focus
57-
#
58-
# # Allows RSpec to persist some state between runs in order to support
59-
# # the `--only-failures` and `--next-failure` CLI options. We recommend
60-
# # you configure your source control system to ignore this file.
61-
# config.example_status_persistence_file_path = "spec/examples.txt"
62-
#
63-
# # Limits the available syntax to the non-monkey patched syntax that is
64-
# # recommended. For more details, see:
65-
# # https://rspec.info/features/3-12/rspec-core/configuration/zero-monkey-patching-mode/
66-
# config.disable_monkey_patching!
67-
#
68-
# # Many RSpec users commonly either run the entire suite or an individual
69-
# # file, and it's useful to allow more verbose output when running an
70-
# # individual spec file.
71-
# if config.files_to_run.one?
72-
# # Use the documentation formatter for detailed output,
73-
# # unless a formatter has already been configured
74-
# # (e.g. via a command-line flag).
75-
# config.default_formatter = "doc"
76-
# end
77-
#
78-
# # Print the 10 slowest examples and example groups at the
79-
# # end of the spec run, to help surface which specs are running
80-
# # particularly slow.
81-
# config.profile_examples = 10
82-
#
83-
# # Run specs in random order to surface order dependencies. If you find an
84-
# # order dependency and want to debug it, you can fix the order by providing
85-
# # the seed, which is printed after each run.
86-
# # --seed 1234
87-
# config.order = :random
88-
#
89-
# # Seed global randomization in this process using the `--seed` CLI option.
90-
# # Setting this allows you to use `--seed` to deterministically reproduce
91-
# # test failures related to randomization by passing the same `--seed` value
92-
# # as the one that triggered the failure.
93-
# Kernel.srand config.seed
9415
end

0 commit comments

Comments
 (0)