spec failed. NoMethodError: undefined method `callback' for #<RSpec::ExampleGroups::O

64 views Asked by At

I want to run callbacks. I have added

   gem 'shoulda-callback-matchers'
   gem 'shoulda-matchers'

in gem file. My code for callbacks is

  describe "#callbacks" do
    it { is_expected.to callback(:set_data).before(:validation) }
    it { is_expected.to callback(:assign_default_to_price).before(:save) }
    it { is_expected.to callback(:set_date).before(:create) }

This code snippet utilizes the 'shoulda-callback-matchers' gem to test the expected behavior of callbacks in my code. The callback matcher checks if the specified callbacks (set_data, assign_default_to_price, set_date) are triggered at the correct points (before(:validation), before(:save), before(:create) respectively) in application's.

All the spec of callback is failing. I am getting error message. One of them is shown below.

Test#callbacks 
     Failure/Error: it { is_expected.to callback(:set_date).before(:create) }
     
     NoMethodError:
       undefined method `callback' for #<RSpec::ExampleGroups::Order::Callbacks "example at ./spec/models/test_spec.rb:109">**

I tried to update gem but no luck. I wrote manual method and its pass my test. read docs and check configuration add config.include(Shoulda::Callback::Matchers::ActiveModel) in spec_helper. still not working.

My ruby version is 3.2.2 and rails 6.0.

0

There are 0 answers