rspec-debugging

Gem codecov

Tools to make debugging RSpec tests easier.


Debug broken specs

Use dit, dcontext, or ddescribe to run a subset of examples and and start the debugger if anything breaks.

require "rspec/debugging"

describe MySpec do
  dit { is_expected.to ... }
end

or set an environment variable to run and debug all specs:

RSPEC_DEBUGGING=true bundle exec rspec


Stop and explore

Drop dit anywhere to start a debugger.

describe MySpec do
  dit
end


Got let variables?

let variables are great, but complexity can obscure their value.

describe RSpec::Debugging do
  describe RSpec::Debugging::LetVariables do
    subject { a }

    let(:a) { "a" }
    let!(:b) { "b" }

    it { is_expected.to be ??? }

    context "when we nest" do
      let(:a) { "A" + b }

      it { is_expected.to be ??? }

      context "...and nest" do
        let(:a) { super() * 2 }

        it { is_expected.to be ??? }
      end
    end

...add a hundred lines of legacy code and then solve for a. Or use tooling :)



let_variables

  • list of variables defined by RSpec let

let_variable_initialized?(name)

  • whether a specified let variable been initialized

let_variable_get(name)

  • the value of a let variable, if initialized

let_variable_values(name)

  • all locations where the specified variable has been defined or redefined, and it's value at each location



Contributing

Yes please :)

  1. Fork it
  2. Create your feature branch (git checkout -b my-feature)
  3. Ensure the tests pass (bundle exec rspec)
  4. Commit your changes (git commit -am 'awesome new feature')
  5. Push your branch (git push origin my-feature)
  6. Create a Pull Request



Inspired by