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

Errors when using describe and :step hook. #28

Open
catmando opened this issue Mar 29, 2016 · 2 comments
Open

Errors when using describe and :step hook. #28

catmando opened this issue Mar 29, 2016 · 2 comments

Comments

@catmando
Copy link

Great Great Gem, thanks so much!

I'm getting the following two problems, I'm documenting together, as I strongly suspect they are related to my configuration.

First Problem: I cannot wrap my steps in a describe:

for example:

require 'spec_helper'

describe 'admin pages', js: true do # remove this and everything works fine

  RSpec::Steps.steps "orders index", js: true do

    it "should login and display the Orders page" do
      size_window(:default)
      @orders = 5.times.collect do
        FactoryGirl.create(:order, :with_valid_payment)
        FactoryGirl.create(:order, :with_valid_payment, :from_one_month_ago)
        FactoryGirl.create(:order, :with_valid_payment, :with_tag)
        FactoryGirl.create(:order, :with_valid_payment, :with_name)
      end
      @admin = FactoryGirl.create(:user, type: "Administrator")
      login(@admin, then_visit: "/admin/orders")
      page.find('h1', text: "Orders")
      page.should have_content("Orders")
    end

    it "should show latest orders" do
      orders = page.all(".order-row", count: 15)
      orders.count.should eq(15)
    end

...

I get this:

/Users/mitch/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.4.2/lib/rspec/core/example_group.rb:240:in `block in define_example_group_method': Creating an isolated context from within a context is not allowed. Change `RSpec.describe` to `describe` or move this to a top-level scope. (RuntimeError)
    from /Users/mitch/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.4.2/lib/rspec/core/dsl.rb:43:in `block in expose_example_group_alias'
    from /Users/mitch/.rvm/gems/ruby-2.3.0/gems/rspec-steps-2.1.1/lib/rspec-steps/builder.rb:10:in `build_example_group'
    from /Users/mitch/.rvm/gems/ruby-2.3.0/gems/rspec-steps-2.1.1/lib/rspec-steps/dsl.rb:19:in `steps'
    from /Users/mitch/railsdev/v4-catprint/spec/integration/admin_spec.rb:5:in `block in <top (required)>'

Note, that if I use the monkeypatch, and simply say steps, I get a slightly different error (perhaps this is a clue?)

/Users/mitch/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.4.2/lib/rspec/core/example_group.rb:675:in `method_missing': undefined method `steps' for RSpec::ExampleGroups::AdminPages:Class (NoMethodError)
    from /Users/mitch/railsdev/v4-catprint/spec/integration/admin_spec.rb:5:in `block in <top (required)>'
    from /Users/mitch/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.4.2/lib/rspec/core/example_group.rb:385:in `module_exec'
    from /Users/mitch/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.4.2/lib/rspec/core/example_group.rb:385:in `subclass'
    from /Users/mitch/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.4.2/lib/rspec/core/example_group.rb:255:in `block in define_example_group_method'
    from /Users/mitch/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.4.2/lib/rspec/core/dsl.rb:43:in `block in expose_example_group_alias'
    from /Users/mitch/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.4.2/lib/rspec/core/dsl.rb:82:in `block (2 levels) in expose_example_group_alias_globally'
    from /Users/mitch/railsdev/v4-catprint/spec/integration/admin_spec.rb:3:in `<top (required)>'

Second (possibly related) problem

In my specs helper if I have:

config.after(:step) do
   ...
end

I get:

/Users/mitch/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.4.2/lib/rspec/core/hooks.rb:591:in `extract_scope_from': You must explicitly give a scope (example, context) or scope alias (each, all) when using symbols as metadata for a hook. (ArgumentError)
    from /Users/mitch/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.4.2/lib/rspec/core/hooks.rb:578:in `scope_and_options_from'
    from /Users/mitch/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.4.2/lib/rspec/core/hooks.rb:449:in `register'
    from /Users/mitch/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.4.2/lib/rspec/core/hooks.rb:272:in `after'
    from /Users/mitch/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.4.2/lib/rspec/core/configuration.rb:1651:in `after'
    from /Users/mitch/railsdev/v4-catprint/spec/spec_helper.rb:193:in `block in <top (required)>'
    from /Users/mitch/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.4.2/lib/rspec/core.rb:97:in `configure'
    from /Users/mitch/railsdev/v4-catprint/spec/spec_helper.rb:123:in `<top (required)>'

Here is the header of the spec_helper.rb if that helps:

require 'rails_helper'
require 'rspec'
require 'rspec/expectations'
require 'factory_girl_rails'
require 'shoulda/matchers'
require 'database_cleaner'
require 'capybara/rspec'
require 'capybara/rails'
require 'support/user_helper'
require 'support/component_test_helpers'
require 'capybara/poltergeist'
require 'billy/rspec'
require 'fixtures/doodlebin/stubs'
require 'timecop'
require "rack_session_access/capybara"
require 'rspec-steps/monkeypatching' # I get the same problems with or without this
...
@IdahoEv
Copy link

IdahoEv commented Mar 29, 2016

Steps is intended, generally, to be used in place of describe; i.e. the steps block is the describe block, but with the added feature of sequentializing the examples within it. So in our practice, we would write your block as:

RSpec::Steps.steps "admin pages orders index", js: true do

That said, I can see cases where you might want to nest steps inside describes in order to simplify your naming. We'll look at whether that can be added in a future version - I'm not immediately certain whether the current architecture can be extended to allow that. Alternatively, we'd welcome a pull request.

@catmando
Copy link
Author

Okay that explains the first one - I will at least do a PR on the Readme since this is very unclear. The readme seems to imply that steps can be used inside a describe block, but you can't have context inside of steps which makes sense.

any clue on the second issue?

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