it_only: running a single example in RSpec
Sometimes you want to focus on just one example in your RSpec file. I had to do this quite often in the last 3 days and I got tired of commenting out stuff back and forth. So, I give you “it_only” example.
module Spec
module DSL
module BehaviourEval
module ModuleMethods
def it(description = :__generate_description, opts = {}, &block)
return if @it_only_found
examples << Example.new(description, opts, &block)
end
# Same as +it+ only blocks all other examples making this the
# only example that would run.
def it_only(description = :__generate_description, opts = {}, &block)
@it_only_found = true
@examples = [Example.new(description, opts, &block)]
end
end
end
end
end
Drop this into your spec_helper.rb and now if you want to focus on a single example, just make it “it_only” instead of “it“.
4 comments.
Leave a Reply