Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

why are steps still randomized #33

Open
jpwynn opened this issue Mar 19, 2017 · 4 comments
Open

why are steps still randomized #33

jpwynn opened this issue Mar 19, 2017 · 4 comments

Comments

@jpwynn
Copy link

jpwynn commented Mar 19, 2017

Given spec/features/test_spec.rb

require 'rails_helper'
require 'rspec-steps'
RSpec::Steps.steps "why are these steps done in random order?" do 
  it "step 1" do
    expect("a").to eq("a")
  end
  it "step 2" do
    expect("a").to eq("a")
  end
  it "step 3" do
    expect("a").to eq("a")
  end
  it "step 4" do
    expect("a").to eq("a")
  end
end

running rspec spec/features/test_spec.rb twice gives:

why are these steps done in random order?
  step 1
  step 4
  step 3
  step 2
Finished in 0.09078 seconds (files took 2.48 seconds to load)
4 examples, 0 failures
Randomized with seed 57459

and then:

why are these steps done in random order?
  step 2
  step 4
  step 1
  step 3
Finished in 0.08662 seconds (files took 2.5 seconds to load)
4 examples, 0 failures
Randomized with seed 39988
@jpwynn
Copy link
Author

jpwynn commented Mar 19, 2017

I'm using Rails 5.0.1 and Rspec 3.5:

rspec (3.5.0)
  rspec-core (~> 3.5.0)
  rspec-expectations (~> 3.5.0)
  rspec-mocks (~> 3.5.0)
rspec-core (3.5.4)
  rspec-support (~> 3.5.0)
rspec-expectations (3.5.0)
  diff-lcs (>= 1.2.0, < 2.0)
  rspec-support (~> 3.5.0)
rspec-mocks (3.5.0)
  diff-lcs (>= 1.2.0, < 2.0)
  rspec-support (~> 3.5.0)
rspec-rails (3.5.2)
  actionpack (>= 3.0)
  activesupport (>= 3.0)
  railties (>= 3.0)
  rspec-core (~> 3.5.0)
  rspec-expectations (~> 3.5.0)
  rspec-mocks (~> 3.5.0)
  rspec-support (~> 3.5.0)
rspec-steps (2.1.1)
  rspec (>= 3.0, < 3.99)
rspec-support (3.5.0)

In rails_helper.rb have:

config.use_transactional_fixtures = false

@IdahoEv
Copy link

IdahoEv commented Mar 19, 2017

Randomizing order is an optional feature of rSpec and isn't appropriate for use with rspec-steps. I would check your ./.rspec and ~/.rspec files for the --order rand command. In a project using rspec-steps, you'll want --order default instead.

@IdahoEv
Copy link

IdahoEv commented Mar 19, 2017

If you really need random order for the rest of your specs, you may be able to tell just the steps specs to run in order by tagging those example groups with { :order => :defined } as described here in the rspec docs https://www.relishapp.com/rspec/rspec-core/docs/configuration/overriding-global-ordering

@jpwynn
Copy link
Author

jpwynn commented Mar 19, 2017

Adding :order => :defined did the trick, thank you.

RSpec::Steps.steps "why are these steps done in random order?", order: :defined do

And that makes perfect sense, however I was fooled by the README saying "The examples above will be run in order" which I understood to mean part of the steps' behinds the scene magic was to prevent randomization.

Perhaps it would be good to show order: :defined in that example code on the REDAME?

If I had to guess, many or most moderately complex projects probably do rely on randomization for everything except the Steps, to better uncover unintentional sequential dependencies, so explicitly addressing the need to disable that for Steps is probably a good idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants