rails / protected_attributes

Protect attributes from mass-assignment in ActiveRecord models.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Test failure with mocha 1.7.0 - Mocha::NotInitializedError: Mocha methods cannot be used outside the context of a test

pravi opened this issue · comments

Originally reported here https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=912253 (it has full log)

pravi@andhaka:~/forge/debian/git/ruby-team/ruby-protected-attributes$ bundle install --path vendor/bundle
Fetching gem metadata from https://rubygems.org/...........
Fetching gem metadata from https://rubygems.org/..
Resolving dependencies...
Fetching rake 12.3.1
Installing rake 12.3.1
Fetching concurrent-ruby 1.1.1
Installing concurrent-ruby 1.1.1
Fetching i18n 0.9.5
Installing i18n 0.9.5
Fetching minitest 5.11.3
Installing minitest 5.11.3
Fetching thread_safe 0.3.6
Installing thread_safe 0.3.6
Fetching tzinfo 1.2.5
Installing tzinfo 1.2.5
Fetching activesupport 4.2.10
Installing activesupport 4.2.10
Fetching builder 3.2.3
Installing builder 3.2.3
Fetching erubis 2.7.0
Installing erubis 2.7.0
Fetching mini_portile2 2.3.0
Installing mini_portile2 2.3.0
Fetching nokogiri 1.8.5
Installing nokogiri 1.8.5 with native extensions
Fetching rails-deprecated_sanitizer 1.0.3
Installing rails-deprecated_sanitizer 1.0.3
Fetching rails-dom-testing 1.0.9
Installing rails-dom-testing 1.0.9
Fetching crass 1.0.4
Installing crass 1.0.4
Fetching loofah 2.2.3
Installing loofah 2.2.3
Fetching rails-html-sanitizer 1.0.4
Installing rails-html-sanitizer 1.0.4
Fetching actionview 4.2.10
Installing actionview 4.2.10
Fetching rack 1.6.11
Installing rack 1.6.11
Fetching rack-test 0.6.3
Installing rack-test 0.6.3
Fetching actionpack 4.2.10
Installing actionpack 4.2.10
Fetching globalid 0.4.1
Installing globalid 0.4.1
Fetching activejob 4.2.10
Installing activejob 4.2.10
Fetching mini_mime 1.0.1
Installing mini_mime 1.0.1
Fetching mail 2.7.1
Installing mail 2.7.1
Fetching actionmailer 4.2.10
Installing actionmailer 4.2.10
Fetching activemodel 4.2.10
Installing activemodel 4.2.10
Fetching arel 6.0.4
Installing arel 6.0.4
Fetching activerecord 4.2.10
Installing activerecord 4.2.10
Using bundler 1.16.1
Fetching metaclass 0.0.4
Installing metaclass 0.0.4
Fetching mocha 1.7.0
Installing mocha 1.7.0
Using protected_attributes 1.1.4 from source at `.`
Fetching thor 0.20.0
Installing thor 0.20.0
Fetching railties 4.2.10
Installing railties 4.2.10
Fetching sprockets 3.7.2
Installing sprockets 3.7.2
Fetching sprockets-rails 3.2.1
Installing sprockets-rails 3.2.1
Fetching rails 4.2.10
Installing rails 4.2.10
Fetching sqlite3 1.3.13
Installing sqlite3 1.3.13 with native extensions
Bundle complete! 7 Gemfile dependencies, 38 gems now installed.
Bundled gems are installed into `./vendor/bundle`
pravi@andhaka:~/forge/debian/git/ruby-team/ruby-protected-attributes$ bundle exec rake
/home/pravi/forge/debian/git/ruby-team/ruby-protected-attributes/vendor/bundle/ruby/2.5.0/gems/activesupport-4.2.10/lib/active_support/core_ext/hash/slice.rb:21: warning: method redefined; discarding old slice
/home/pravi/forge/debian/git/ruby-team/ruby-protected-attributes/vendor/bundle/ruby/2.5.0/gems/activesupport-4.2.10/lib/active_support/core_ext/hash/keys.rb:8: warning: method redefined; discarding old transform_keys
/home/pravi/forge/debian/git/ruby-team/ruby-protected-attributes/vendor/bundle/ruby/2.5.0/gems/activesupport-4.2.10/lib/active_support/core_ext/hash/keys.rb:19: warning: method redefined; discarding old transform_keys!
/home/pravi/forge/debian/git/ruby-team/ruby-protected-attributes/vendor/bundle/ruby/2.5.0/gems/activesupport-4.2.10/lib/active_support/core_ext/object/duplicable.rb:111: warning: BigDecimal.new is deprecated; use Kernel.BigDecimal method instead.
/home/pravi/forge/debian/git/ruby-team/ruby-protected-attributes/vendor/bundle/ruby/2.5.0/gems/activesupport-4.2.10/lib/active_support/core_ext/enumerable.rb:20: warning: method redefined; discarding old sum
/home/pravi/forge/debian/git/ruby-team/ruby-protected-attributes/vendor/bundle/ruby/2.5.0/gems/arel-6.0.4/lib/arel/visitors/informix.rb:20: warning: assigned but unused variable - froms
/home/pravi/forge/debian/git/ruby-team/ruby-protected-attributes/lib/active_record/mass_assignment_security/associations.rb:82: warning: method redefined; discarding old build_record
/home/pravi/forge/debian/git/ruby-team/ruby-protected-attributes/vendor/bundle/ruby/2.5.0/gems/activerecord-4.2.10/lib/active_record/associations/through_association.rb:89: warning: previous definition of build_record was here
/home/pravi/forge/debian/git/ruby-team/ruby-protected-attributes/lib/active_record/mass_assignment_security/associations.rb:116: warning: method redefined; discarding old options_for_through_record
/home/pravi/forge/debian/git/ruby-team/ruby-protected-attributes/vendor/bundle/ruby/2.5.0/gems/activerecord-4.2.10/lib/active_record/associations/has_many_through_association.rb:106: warning: previous definition of options_for_through_record was here
Run options: --seed 29684

# Running:

.........................................................................................EEE.................................................................................................................

   1) derived wrapped keys from specified model
      Mocha::NotInitializedError: Mocha methods cannot be used outside the context of a test
          /home/pravi/forge/debian/git/ruby-team/ruby-protected-attributes/test/accessible_params_wrapper_test.rb:54:in `block in test_derived_wrapped_keys_from_specified_model'
          /home/pravi/forge/debian/git/ruby-team/ruby-protected-attributes/test/accessible_params_wrapper_test.rb:9:in `with_default_wrapper_options'
      # test/accessible_params_wrapper_test.rb:54
      # test/accessible_params_wrapper_test.rb:9
      # test/accessible_params_wrapper_test.rb:53

   2) derived wrapped keys from matching model
      Mocha::NotInitializedError: Mocha methods cannot be used outside the context of a test
      # test/accessible_params_wrapper_test.rb:41

   3) accessible wrapped keys from matching model
      Mocha::NotInitializedError: Mocha methods cannot be used outside the context of a test
      # test/accessible_params_wrapper_test.rb:67

Finished in 0.761185s, 269.3169 runs/s, 960.3448 assertions/s.
205 runs, 731 assertions, no failures, 3 errors, no skips

Failed Tests:

rake TEST=/home/pravi/forge/debian/git/ruby-team/ruby-protected-attributes/test/accessible_params_wrapper_test.rb TESTOPTS="--name=test_derived_wrapped_keys_from_specified_model"
rake TEST=/home/pravi/forge/debian/git/ruby-team/ruby-protected-attributes/test/accessible_params_wrapper_test.rb TESTOPTS="--name=test_derived_wrapped_keys_from_matching_model"
rake TEST=/home/pravi/forge/debian/git/ruby-team/ruby-protected-attributes/test/accessible_params_wrapper_test.rb TESTOPTS="--name=test_accessible_wrapped_keys_from_matching_model"

rake aborted!
Command failed with status (1)
/home/pravi/forge/debian/git/ruby-team/ruby-protected-attributes/vendor/bundle/ruby/2.5.0/gems/rake-12.3.1/exe/rake:27:in `<top (required)>'
Tasks: TOP => default => test
(See full trace by running task with --trace)

@rafaelfranca, would it be possible to update the tests? We'd like to use mocha 1.7 in Debian. If it is not possible, we'll disable the tests. In Debian, we prefer to use a single version of mocha for all gems (saves maintenance effort).

I don't think so. The tests are not doing anything wrong. As you can see in the code the mocks are being setup inside a test context.

@rafaelfranca I opened an issue with mocha. Lets see what they say.