I have a model `A` which `belongs_to` `B`. And I'm trying to write a unit test 
with `A` as `subject`:

```
expect(subject.b).to receive(:to_s)
```

Yet this spec always fails, saying that the instance of `B` did not receive the 
message, notwithstanding I have put `binding.pry` in the actual code to run and 
verified that `a.b.to_s` gets called.

```
class A
  def validate_my_field
    binding.pry # this fires
    if b.to_s
        super
    end
end
```

I have even tried:

```
expect(a).to receive(:b).and_return(b)
expect(b).to receive(:to_s)
```

And:

```
expect_any_instance_of(b.class).to receive(:to_s)
```

Yet all expectations for `to_s` fail. Why could this be?

I'm in Rails 6 with Rspec 3.8.0.

-- 
You received this message because you are subscribed to the Google Groups 
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rspec/b968b2c9-993b-40d2-94cc-2582a54e7397%40googlegroups.com.

Reply via email to