I'am on upgrading a Ruby on Rails system from Rails 5 to 6 and as the first step I'm upgrading all gems. As I run my tests, I get the following message:
Deprecation Warnings:
The implicit block expectation syntax is deprecated, you should pass a block to `expect` to use the provided block expectation matcher (change `FileAsset.count`), or the matcher must implement `supports_value_expectations?`.
The test is passed, but I don't understand, what I have to do to avoid the deprecation message. The referenced block in my spec:
describe "Save should not create FileAsset" do
subject {
lambda {
click_button I18n.t(:button_attach_files)
page.should have_error_message()
}
}
it { should_not change(FileAsset, :count) }
end
What should I use instead of it { should_not change(FileAsset, :count) }
?
Current versions:
rails 5.2.8.1
rspec 3.12.0
rspec-activemodel-mocks 1.1.0
rspec-core 3.12.0
rspec-expectations 3.12.2
rspec-mocks 3.12.2
rspec-rails 5.1.2
cucumber 8.0.0
cucumber-ci-environment 9.1.0
cucumber-core 11.0.0
cucumber-cucumber-expressions 15.2.0
cucumber-gherkin 23.0.1
cucumber-html-formatter 19.2.0
cucumber-messages 18.0.0
cucumber-rails 2.6.1
cucumber-tag-expressions 4.1.0
rspec-support 3.12.0
CodePudding user response:
What about
describe "Save should not create FileAsset" do
subject {
click_button I18n.t(:button_attach_files)
page.should have_error_message()
}
it { should_not change(FileAsset, :count) }
end
Also you should prefer more recent syntax. Like:
describe "save" do
it "does not create FileAsset" do
expect {
click_button I18n.t(:button_attach_files)
}.not_to change { FileAsset.count }
expect(page).to have_error_message()
end
end