Here are some simplified snippets of my test environment:
group :development, :test do
gem 'rspec-rails' # (3.4.2)
end
group :test do
gem 'shoulda-matchers' # (3.1.1)
end
RSpec.describe GitRepositoryLocationsController do
describe 'POST #create', :logged_in do
before { post :create, params }
context 'when the GitRepositoryLocation is invalid' do
let(:params) { ... }
it { is_expected.to set_flash }
end
end
end
But I get the error
undefined local variable or method `set_flash' for #<RSpec::ExampleGroups::GitRepositoryLocationsController::POSTCreate::WhenTheGitRepositoryLocationIsInvalid:0x007fc371af87a0>
It works when I include the module in the spec file
include Shoulda::Matchers::ActionController
Hi @dideler,
Perhaps you've not configured Shoulda correctly? Have you added the following in your spec/rails_helper.rb, for example?
Shoulda::Matchers.configure do |config|
config.integrate do |with|
with.test_framework :rspec
with.library :rails
end
end
The Getting Started Guide has more info.
Do other shoulda-matchers fail to work too, or is it just set_flash?
That solves it, thanks. Missed that step somehow.
Most helpful comment
Hi @dideler,
Perhaps you've not configured
Shouldacorrectly? Have you added the following in yourspec/rails_helper.rb, for example?The Getting Started Guide has more info.
Do other shoulda-matchers fail to work too, or is it just
set_flash?