Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spec: Always include spec_helper #1201

Conversation

olleolleolle
Copy link
Contributor

@olleolleolle olleolleolle commented Sep 18, 2017

Summary

This PR does one thing: uses the options file .rspec to always include spec_helper. Also: removes the require 'spec_helper' from each spec file which has it.

Details

I was asking myself: "Do we pay any special cost for having the spec helper in each file?" and "Can we have one require instead of 30?"

Motivation and Context

"Can we have one require instead of 30?"

How Has This Been Tested?

Ran the test suite locally.

Types of changes

  • Refactor (code change that does not change external functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

@mxygem
Copy link
Member

mxygem commented Sep 19, 2017

LGTM and 👍 for reducing redundancy! @olleolleolle What were the answers to the questions you asked yourself? :p

@mattwynne
Copy link
Member

One reason to have explicit dependencies is performance. If a unit test doesn't need to load spec_helper.rb it will run faster in isolation if it isn't forced to.

It depends on what our spec does whether this will have significant impact or not.

Nevertheless, I personally find it a good practice to minimise dependencies wherever possible.

I've forgotten (and I'm on a phone so can't check) - what does our spec helper actually do?

@olleolleolle
Copy link
Contributor Author

It requires a few files - cucumber among them. Decides on ANSI coloring. Adds a "pending" method to decide whether or not to run a test.

# frozen_string_literal: true
ENV['CUCUMBER_COLORS'] = nil
$:.unshift(File.dirname(__FILE__))

# For Travis....
require 'cucumber/encoding'

require 'simplecov_setup'

require 'pry'

require 'cucumber'

RSpec.configure do |c|
  c.before do
    ::Cucumber::Term::ANSIColor.coloring = true
  end
end

module RSpec
  module WorkInProgress
    def pending_under(platforms, reason, &block)
      if [platforms].flatten.map(&:to_s).include? RUBY_PLATFORM
        pending "pending under #{platforms.inspect} because: #{reason}", &block
      else
        yield
      end
    end
  end
end

I'm happy to not merge this change, if that's your take on it.

@Ben-Behar
Copy link
Contributor

It sounds like a more fundamental question to ask is: Should the unit tests be runnable in more than one specific environment?

Moving dependencies to .rspec results in the ability to run the tests with another .rspec file, and thus a slightly different environment. While this can be a neat way to specify configuration options based on context, it might lead to a path of surprise to an inexperienced developer. Thoughts?

@mattwynne
Copy link
Member

What would be some examples of those different environments @Ben-Behar?

@Ben-Behar
Copy link
Contributor

Ben-Behar commented Sep 21, 2017

Well, a trick that I have seen before is to have a .rspec just for development which includes helpful debugging tools, such as require 'pry' or possibly some debugging monkeypatch (def fail ; binding.pry ; end).
Then during the build/testing process, no .rspec file is given, to ensure that the tests are executed in the most minimal environment.

@olleolleolle
Copy link
Contributor Author

I'll close this PR. Thanks for the interest in it.

We'll manage!

@olleolleolle olleolleolle deleted the fix/just-include-spec-helper branch September 27, 2017 21:40
@lock
Copy link

lock bot commented Oct 24, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 24, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants