cabbage-ex / cabbage

Story BDD tool for executing elixir in ExUnit
MIT License
144 stars 34 forks source link

state is updated #32

Closed hanskenis closed 7 years ago

hanskenis commented 7 years ago

it seems like the state passed into a test is not always the state given in the setup function. When the state is updated, it uses that state in the following steps. Even across different scenarios.

reproduce

   1 Feature: Bug
   2
   3 Scenario: No state change
   4     Given start state
   5     Then the state is not changed
   6
   7   Scenario: State change
   8     Given start state
   9     When i change state
  10     Then state is changed
test/features/bug_test.exs

   1 defmodule CabbageTest.BugTest do
   2   use Cabbage.Feature, async: true, file: "bug.feature"
   3
   4   setup do
   5     {:ok, params: "start"}
   6   end
   7
   8   defgiven ~r/^start state$/, _vars, %{params: params } do
   9     IO.inspect params
  10   end
  11
  12  defthen ~r/^the state is not changed$/, _vars, %{params: params} do
  13    assert params == "start"
  14   end
  15
  16   defwhen ~r/^i change state$/, _vars, state do
  17     {:ok, %{params: "changed"}}
  18   end
  19
  20   defthen ~r/^state is changed$/, _vars, %{params: params} do
  21     assert params == "changed"
  22   end
  23 end

now when the scenario with state change is executed before the other, it fails. you can test with mix test --seed 394964

Thx!

mgwidmann commented 7 years ago

Hmm, interesting. They should be using different agents for the state but perhaps something is not right and they somehow are (and with the async: true it randomizes the problem). I'll take a look into it soon. Thanks for reporting.