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

Add example group for features #632

Closed
wants to merge 3 commits into from

Conversation

jnicklas
Copy link
Contributor

@jnicklas jnicklas commented Nov 5, 2012

This fixes various issues with the integration between RSpec and Capybara 2.0.

  • It includes Route helpers, these were previously unavailable, due to the fact that the only reason they are available in request spec is that those delegate via method_missing to an IntegrationTest instance.
  • It adds the :feature type to all features. This way people can include module into :type => :feature examples and they will work when their specs are places in this folder.

David previously commented that he didn't want to add Capybara specific behaviour outside of rspec/rails/capybara. I was careful to avoid doing that. The feature example group does not explicitly include Capybara, instead, Capybara is included due to Capybara itself hooking into :type => :feature. This is much cleaner than the way it was before.

I tested this against both a freshly generated Rails app, as well as an existing, rather large project, both worked well.

This fixes various issues with the integration between RSpec and Capybara 2.0.

- It includes Route helpers, these were previously unavailable, due to the fact that the only reason they are available in request spec is that those delegate via method_missing to an IntegrationTest instance.

- It adds the `:feature` type to all features. This way people can include module into `:type => :feature` examples and they will work when their specs are places in this folder.

David previously commented that he didn't want to add Capybara specific behaviour outside of `rspec/rails/capybara`. I was careful to avoid doing that. The feature example group does not explicitly include Capybara, instead, Capybara is included due to Capybara itself hooking into `:type => :feature`. This is much cleaner than the way it was before.

I tested this against both a freshly generated Rails app, as well as an existing, rather large project, both worked well.
@bobbytables
Copy link

+1

@jnicklas
Copy link
Contributor Author

jnicklas commented Nov 6, 2012

Saw that Travis failed for earlier Rails versions, so I pushed a fix.

@alindeman
Copy link
Contributor

I initially thought a FeatureExampleGroup was a good idea, then waffled after talking to @dchelimsky, but I think URL helpers are a compelling reason to create one.

If capybara is not present, FeatureExampleGroup is still usable as a bare bones example group .. and with route helpers. I'm not sure how likely it is for someone to use it this way, but the introduction of another type of example group that only includes capybara if it's present doesn't worry me much.

Unless there are strong objections, I will revert my earlier work in 96e1c33 and go with @jnicklas's.

@dchelimsky
Copy link
Contributor

@alindeman I have no objection.

@jnicklas thanks for the pull request - really appreciate the collaborative effort here. Cheers!

@dchelimsky
Copy link
Contributor

One additional consideration (which can be addressed in a separate pull/commit) is that FeatureExampleGroup is currently only meaningful when Capybara is loaded - there are no functions for simulating requests otherwise - so I think we probably want to raise an error if Capybara is not loaded. WDYT?

@jnicklas
Copy link
Contributor Author

jnicklas commented Nov 7, 2012

It seems to me like there is no harm if someone wants to use the FeatureExampleGroup without Capybara. Especially since rspec-rails tries to load capybara, so if it is available, it will be loaded anyway. Someone could use selenium-webdriver directly, for example. I don't see why that should cause a failure.

@dchelimsky
Copy link
Contributor

My concern is confusion caused by creating a file in spec/features without Capybara installed or loaded and not understanding why there is no get/post/put/delete/head or visit.

@jnicklas
Copy link
Contributor Author

jnicklas commented Nov 9, 2012

@dchelimsky: would this be an acceptable solution: jnicklas/rspec-rails@jnicklas:feature-example-group...jnicklas:with-fake-capybara Most people are going to call visit first, so hinting at Capybara not being loaded there might be sufficient.

If you approve, I can send a pull request for that too, but let's get this one merged, so that we can move forward!

@dchelimsky
Copy link
Contributor

@jnicklas works for me. @alindeman, wdyt?

@alindeman
Copy link
Contributor

I like it. I'm pull that in, as well as fixing my quasi-conflicting changes, now. Thanks so much @jnicklas and other Capybara folks for working this, and I apologize about the delay.

alindeman added a commit to alindeman/rspec-rails that referenced this pull request Nov 9, 2012
This reverts commit 96e1c33.

* We'll instead use an implementation that adds a proper
  FeatureExampleGroup (see rspec#632)
@alindeman
Copy link
Contributor

@jnicklas, would you mind performing similar tests against the code I just pushed to https://github.com/alindeman/rspec-rails/tree/with-fake-capybara? I kept much of your implementation, but tweaked it a bit based on the Rails code I originally wrote it against.

If it works and you feel good about it, I'll merge that.

Feel free to call me out on anything you see that might be an issue.

@jnicklas
Copy link
Contributor Author

@alindeman looks good to me! Good catch on the host stuff, I didn't consider that at all.

@alindeman
Copy link
Contributor

Committed with 0fda98b. I will spend some time writing up more docs on this soon, but hopefully that helps remove road blocks. If not, ping me!

@alindeman alindeman closed this Nov 10, 2012
@alindeman
Copy link
Contributor

I just pushed some new docs for feature specs. Reviews welcomed: 6e68bdd

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.

4 participants