Search code examples
rubyrspecrspec-rails

Call yield from another do ...end block


I try to define own 'context' method in Rspec. Have next:

module MiscSpecHelper
  def its_ok
    context "if everything is OK" do
      yield
    end
  end
end

in spec file:

describe "GET index" do
  its_ok do
    it "has a 200 status code" do
      get :index
      expect(response.status).to eq(200)
    end
  end
end

I got:

GET index
  has a 200 status code

I expect:

GET index
  if everything is OK
    has a 200 status code

Why does it ignore my 'context' description?


Solution

  • module MiscSpecHelper
      def its_ok(&block)
        context "if everything is OK", &block
      end
    end