Myron,

Thanks for the help, but the same thing still occurs. I had tried expect 
syntax and just retried.

expect(User).to receive(:find_by_user_id_and_type).with(42, 
'GREAT_USER').and_return(user)

As before, the result is.

ActiveRecord::StatementInvalid: Could not find table 'users'
/Users/mp/.rvm/gems/ruby-2.1.2_hc-2.1.2/gems/activerecord-3.2.21/lib/active_record/connection_adapters/sqlite_adapter.rb:472:in
 
`table_structure'
/Users/mp/.rvm/gems/ruby-2.1.2_hc-2.1.2/gems/activerecord-3.2.21/lib/active_record/connection_adapters/sqlite_adapter.rb:346:in
 
`columns'
/Users/mp/.rvm/gems/ruby-2.1.2_hc-2.1.2/gems/activerecord-3.2.21/lib/active_record/connection_adapters/schema_cache.rb:12:in
 
`block in initialize'
/Users/mp/.rvm/gems/ruby-2.1.2_hc-2.1.2/gems/activerecord-3.2.21/lib/active_record/model_schema.rb:229:in
 
`yield'
/Users/mp/.rvm/gems/ruby-2.1.2_hc-2.1.2/gems/activerecord-3.2.21/lib/active_record/model_schema.rb:229:in
 
`columns'
/Users/mp/.rvm/gems/ruby-2.1.2_hc-2.1.2/gems/activerecord-3.2.21/lib/active_record/model_schema.rb:249:in
 
`column_names'
/Users/mp/.rvm/gems/ruby-2.1.2_hc-2.1.2/gems/activerecord-3.2.21/lib/active_record/model_schema.rb:262:in
 
`column_methods_hash'
/Users/mp/.rvm/gems/ruby-2.1.2_hc-2.1.2/gems/activerecord-3.2.21/lib/active_record/dynamic_matchers.rb:74:in
 
`all_attributes_exists?'
/Users/mp/.rvm/gems/ruby-2.1.2_hc-2.1.2/gems/activerecord-3.2.21/lib/active_record/dynamic_matchers.rb:27:in
 
`method_missing'
./lib/hc/qb/create_or_update_invoice.rb:17:in `create_or_update'
./spec/create_or_update_invoice_spec.rb:233:in `block (4 levels) in <top 
(required)>'
-e:1:in `load'
-e:1:in `<main>'

Unlike 1.x, if 3.4 even touches an ActiveRecord class it tries to load it 
from the schema, before it is actually used.

Thanks,
Adam

On Tuesday, February 2, 2016 at 11:46:49 AM UTC-8, Myron Marston wrote:
>
> In rspec 3.2, we changed to 
>>     allow(User).to receive(:find_by_user_id_and_type).with(42, 
>> 'GREAT_USER').and_return(user)
>
>
> This is not equivalent to what you had before. The equivalent of 
> `User.should_receive` in the new syntax is `expect(User).to receive`. 
>  `allow` is the equivalent of a stub.
>
> As for the error you're getting: I believe it is related to verifying 
> doubles.  It is trying to validate that `find_by_user_id_and_type` is a 
> valid method -- but to verify that, the schema must be loaded to see if the 
> model has `user_id` and `type` fields.  If you don't want partial doubles 
> to have that kind of verification, you can turn it off with a config option:
>
>
> https://www.relishapp.com/rspec/rspec-mocks/docs/verifying-doubles/partial-doubles
>
> HTH,
> Myron
>
> On Tue, Feb 2, 2016 at 11:38 AM, Adam Perry-Pelletier <
> [email protected] <javascript:>> wrote:
>
>> In old RSpec, in a Rails Mountable Engine project with no database 
>> underneath. We have the following expectation set up.
>>
>>     User.should_receive(:find_by_user_id_and_type).with(42, 
>> 'GREAT_USER').and_return(user)
>>
>> The above worked fine.
>>
>> In rspec 3.2, we changed to 
>>
>>     allow(User).to receive(:find_by_user_id_and_type).with(42, 
>> 'GREAT_USER').and_return(user)
>>
>> This now fails with the error: 
>>
>>     ActiveRecord::StatementInvalid: Could not find table 'users'
>>
>> It appears in rspec 3.4 when the expectation is set up, rspec does try to 
>> load the ActiveRecord properties from the database. The old rspec did not 
>> do this. This allowed us to write rspec tests against a Rails Mountable 
>> Engine project without actually having to load and configure a test 
>> database. The database for this project is loaded and available in the main 
>> project which uses this subproject.
>>
>> Thanks in advance for any help.
>> Adam
>>
>>
>> -- 
>> 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] <javascript:>.
>> To post to this group, send email to [email protected] <javascript:>
>> .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/rspec/68e6bdcf-a228-45c4-bcd8-c12b1e31af1e%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/rspec/68e6bdcf-a228-45c4-bcd8-c12b1e31af1e%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rspec/00854e19-2580-4567-96fe-1793e6751f4f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to