antonmi / espec

Elixir Behaviour Driven Development
Other
808 stars 62 forks source link

shared not available in top-level before block #229

Closed anthonator closed 7 years ago

anthonator commented 7 years ago

Currently, it's not possible to access shared in a top-level before block.

For instance:

defmodule MySpecs do
  use ESpec

  before do: IO.inspect(shared) # undefined function shared/0
end

My main use case is being able to access the options passed into ESpec.

defmodule MySpecs do
  use ESpec, async: true

  before do: IO.inspect(shared[:async])
end
antonmi commented 7 years ago

Hi, @anthonator ! It's strange! I've just tried to reproduce with

defmodule SomeSpec do
  use ESpec, async: true

  before do
    IO.inspect("top before")
    IO.inspect(shared)
  end

  context "context" do
    before do
      IO.inspect("context before")
      IO.inspect(shared)
    end

    it do: expect(1).to eq(1)
  end
end

And it works well:

"top before"
%{async: true}
"context before"
%{async: true}

Could you please send a content of spec_helper.exs

anthonator commented 7 years ago

I think this is something on my end. I'm going to close this for now. If I can't resolve it I'll open another issue with more information.

antonmi commented 7 years ago

Sure!