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

Allow deeper group nesting in RSpec #7

Merged
merged 1 commit into from
Oct 2, 2017
Merged

Conversation

no-reply
Copy link

@no-reply no-reply commented Oct 2, 2017

The reason for restricting nesting is presumably to flag complex test setups
that indicate a smell in the tested code. Three levels are
allowed

to accomodate this common style:

describe MyClass do
  describe '#a_method' do
    context 'some application state' do
      # examples
    end

    context 'other application state' do
      # examples
    end
  end
end

My experience has been that a slightly more complex setup in a Rails
application (particularly for model and controller specs) is more a fact of life
than a code smell. Four levels accommodates code like:

describe MyController, type: :controller do
  context 'when logged in as admin' do
    include_context 'as admin' do

    ...
  end

  context 'when logged is as other_role' do
    include_context 'as other_role' do
    ...
  end
end

Using my current application as a gague, my sense is that the additional level
of nesting addresses the common cases.

The reason for restricting nesting is presumably to flag complex test setups
that indicate a smell in the tested code. [Three levels are
allowed](rubocop/rubocop-rspec#207 (comment))
to accomodate this common style:

```ruby
describe MyClass do
  describe '#a_method' do
    context 'some application state' do
      # examples
    end

    context 'other application state' do
      # examples
    end
  end
end
```

My experience has been that a slightly more complex setup in a Rails
application (particularly for model and controller specs) is more a fact of life
than a code smell. Four levels accommodates code like:

```ruby
describe MyController, type: :controller do
  context 'when logged in as admin' do
    include_context 'as admin' do

    ...
  end

  context 'when logged is as other_role' do
    include_context 'as other_role' do
    ...
  end
end
```

Using my current application as a gague, my sense is that the additional level
of nesting addresses the common cases.
no-reply pushed a commit to curationexperts/epigaea that referenced this pull request Oct 2, 2017
A related PR with details and reasoning for the change is at:
samvera/bixby#7
@no-reply no-reply merged commit 2ff6560 into master Oct 2, 2017
@no-reply no-reply deleted the rspec-nested-contexts branch October 2, 2017 21:31
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

Successfully merging this pull request may close these issues.

1 participant