I have a simple test feature called test_feature_spec.rb
:
(this is just for getting to the point of this SO question... the actual specs are much longer, actual feature specs)
require "features_helper"
RSpec.feature "Simple Feature", type: :feature do
scenario "a test scenario" do
get "/"
end
end
I can do various Rails-y things, including capybara-driven things (like visit such_n_such_path
). However the above crashes:
Failures:
1) Simple Feature a test scenario
Failure/Error: get "/"
NoMethodError:
undefined method `get' for #<RSpec::ExampleGroups::SimpleFeature:0x000000011a799788>
Did you mean? gets
gem
If I simply change it from type: :feature
to type: :request
it works just fine:
> rspec spec/features/test_feature_spec.rb
.
Finished in 0.64913 seconds (files took 5.82 seconds to load)
1 example, 0 failures
It seems that with type
=> request
Rails or Rspec loads some stuff to allow calling controller routes, but it doesn't with type
=> feature
.
Is there a way to load those helper methods (like get
and post
and such) but still leave the feature as type: :feature
?
I know I could just change it to type: :request
but technically these are feature specs, even though for some of them, to set up some state or do whatever, they need to call certain URLs.
visit
instead ofget
when using paths - can you try that?get
is usually used with:new
etc - kuwantumvisit
worked, but my problem is that I want to be able to do direct HTTP calls of GET or POST (or whatever) type.visit
is for driving an end-user browser like interaction. Anyway, I figured out an easy fix (see my answer below) - Dan Sharp