RobL Vs

Background

customising spec_helper.rb

I’ve never really looked at spec_helper.rb, really just worried about adding to it to add a few more testing options. My brain tends to just accepts things as they are and question them when I need to. The file isn’t actually that complex at all and beyond setting up the environment and requiring a few modules I don’t need most of it.

 1# This file is copied to ~/spec when you run 'ruby script/generate rspec'
 2# from the project root directory.
 3ENV["RAILS_ENV"] ||= 'test'
 4require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT)
 5require 'spec/autorun'
 6require 'spec/rails'
 7
 8# Requires supporting files with custom matchers and macros, etc,
 9# in ./support/ and its subdirectories.
10Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
11
12Spec::Runner.configure do |config|
13  # If you're not using ActiveRecord you should remove these
14  # lines, delete config/database.yml and disable :active_record
15  # in your config/boot.rb
16  config.use_transactional_fixtures = true
17  config.use_instantiated_fixtures  = false
18  config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
19
20  # == Fixtures
21  #
22  # You can declare fixtures for each example_group like this:
23  #   describe "...." do
24  #     fixtures :table_a, :table_b
25  #
26  # Alternatively, if you prefer to declare them only once, you can
27  # do so right here. Just uncomment the next line and replace the fixture
28  # names with your fixtures.
29  #
30  # config.global_fixtures = :table_a, :table_b
31  #
32  # If you declare global fixtures, be aware that they will be declared
33  # for all of your examples, even those that don't use them.
34  #
35  # You can also declare which fixtures to use (for example fixtures for test/fixtures):
36  #
37  # config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
38  #
39  # == Mock Framework
40  #
41  # RSpec uses it's own mocking framework by default. If you prefer to
42  # use mocha, flexmock or RR, uncomment the appropriate line:
43  #
44  # config.mock_with :mocha
45  # config.mock_with :flexmock
46  # config.mock_with :rr
47  #
48  # == Notes
49  #
50  # For more information take a look at Spec::Runner::Configuration and Spec::Runner
51end

So now here’s my one now, I don’t need custom matcher includes as remarkable has plenty for me to get on with, and I’ve replaced the default fixtures which I don’t use anymore set up with machinist .

 1# default
 2ENV["RAILS_ENV"] ||= 'test'
 3require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT)
 4require 'spec/autorun'
 5require 'spec/rails'
 6
 7# machinist
 8require 'machinist/active_record'
 9require 'faker'
10require File.dirname(__FILE__) + '/blueprints'
11
12# remarkable
13require 'remarkable_rails'