mutant
mutant copied to clipboard
I get an error when running mutant in Rails
I am trying to use mutant-rspec in a Rails project. So, that means I have an app directory and for example inside it I have a models directory and inside the user.rb class. And the test for this file is in spec/models/user_spec.rb.
I added the gem to the Gemfile and then I tried to mutate user tests running:
bundle exec mutant --use rspec User
and I get the following output:
Module#name from: XPath::HTML returned name(.). Fix your lib to follow normal ruby semantics!
{Module,Class}#name should return resolvable constant name as String or nil
Module#name from: XPath returned name(.). Fix your lib to follow normal ruby semantics!
{Module,Class}#name should return resolvable constant name as String or nil
Mutant configuration:
Matcher: #<Mutant::Matcher::Config match_expressions: [User]>
Integration: Mutant::Integration::Rspec
Jobs: 2
Includes: []
Requires: []
Subjects: 74
Mutations: 5742
Results: 0
Kills: 0
Alive: 0
Runtime: 0.00s
Killtime: 0.00s
Overhead: Inf%
Mutations/s: 0.00
Coverage: 100.00%
Active subjects: 0
/usr/lib64/ruby/gems/2.4.0/gems/mutant-rspec-0.8.13/lib/mutant/integration/rspec.rb:124:in `parse_expression': undefined method `captures' for nil:NilClass (NoMethodError)
Did you mean? capture
from /usr/lib64/ruby/gems/2.4.0/gems/mutant-rspec-0.8.13/lib/mutant/integration/rspec.rb:109:in `parse_example'
from /usr/lib64/ruby/gems/2.4.0/gems/mutant-rspec-0.8.13/lib/mutant/integration/rspec.rb:88:in `block in all_tests_index'
from /usr/lib64/ruby/gems/2.4.0/gems/mutant-rspec-0.8.13/lib/mutant/integration/rspec.rb:87:in `each'
from /usr/lib64/ruby/gems/2.4.0/gems/mutant-rspec-0.8.13/lib/mutant/integration/rspec.rb:87:in `each_with_index'
from /usr/lib64/ruby/gems/2.4.0/gems/mutant-rspec-0.8.13/lib/mutant/integration/rspec.rb:87:in `each_with_object'
from /usr/lib64/ruby/gems/2.4.0/gems/mutant-rspec-0.8.13/lib/mutant/integration/rspec.rb:87:in `all_tests_index'
from /usr/lib64/ruby/gems/2.4.0/gems/memoizable-0.4.2/lib/memoizable/method_builder.rb:117:in `call'
from /usr/lib64/ruby/gems/2.4.0/gems/memoizable-0.4.2/lib/memoizable/method_builder.rb:117:in `block (3 levels) in create_memoized_method'
from /usr/lib64/ruby/gems/2.4.0/gems/memoizable-0.4.2/lib/memoizable/memory.rb:63:in `block (3 levels) in fetch'
from /usr/lib64/ruby/gems/2.4.0/gems/thread_safe-0.3.6/lib/thread_safe/cache.rb:56:in `fetch'
from /usr/lib64/ruby/gems/2.4.0/gems/memoizable-0.4.2/lib/memoizable/memory.rb:62:in `block (2 levels) in fetch'
from /usr/lib64/ruby/2.4.0/monitor.rb:214:in `mon_synchronize'
from /usr/lib64/ruby/gems/2.4.0/gems/memoizable-0.4.2/lib/memoizable/memory.rb:61:in `block in fetch'
from /usr/lib64/ruby/gems/2.4.0/gems/thread_safe-0.3.6/lib/thread_safe/cache.rb:56:in `fetch'
from /usr/lib64/ruby/gems/2.4.0/gems/memoizable-0.4.2/lib/memoizable/memory.rb:60:in `fetch'
from /usr/lib64/ruby/gems/2.4.0/gems/memoizable-0.4.2/lib/memoizable/method_builder.rb:116:in `block (2 levels) in create_memoized_method'
from /usr/lib64/ruby/gems/2.4.0/gems/mutant-rspec-0.8.13/lib/mutant/integration/rspec.rb:77:in `all_tests'
from /usr/lib64/ruby/gems/2.4.0/gems/memoizable-0.4.2/lib/memoizable/method_builder.rb:117:in `call'
from /usr/lib64/ruby/gems/2.4.0/gems/memoizable-0.4.2/lib/memoizable/method_builder.rb:117:in `block (3 levels) in create_memoized_method'
from /usr/lib64/ruby/gems/2.4.0/gems/memoizable-0.4.2/lib/memoizable/memory.rb:63:in `block (3 levels) in fetch'
from /usr/lib64/ruby/gems/2.4.0/gems/thread_safe-0.3.6/lib/thread_safe/cache.rb:56:in `fetch'
from /usr/lib64/ruby/gems/2.4.0/gems/memoizable-0.4.2/lib/memoizable/memory.rb:62:in `block (2 levels) in fetch'
from /usr/lib64/ruby/2.4.0/monitor.rb:214:in `mon_synchronize'
from /usr/lib64/ruby/gems/2.4.0/gems/memoizable-0.4.2/lib/memoizable/memory.rb:61:in `block in fetch'
from /usr/lib64/ruby/gems/2.4.0/gems/thread_safe-0.3.6/lib/thread_safe/cache.rb:56:in `fetch'
from /usr/lib64/ruby/gems/2.4.0/gems/memoizable-0.4.2/lib/memoizable/memory.rb:60:in `fetch'
from /usr/lib64/ruby/gems/2.4.0/gems/memoizable-0.4.2/lib/memoizable/method_builder.rb:116:in `block (2 levels) in create_memoized_method'
from /usr/lib64/ruby/gems/2.4.0/gems/mutant-0.8.13/lib/mutant/selector/expression.rb:14:in `block in call'
from /usr/lib64/ruby/gems/2.4.0/gems/mutant-0.8.13/lib/mutant/selector/expression.rb:13:in `each'
from /usr/lib64/ruby/gems/2.4.0/gems/mutant-0.8.13/lib/mutant/selector/expression.rb:13:in `call'
from /usr/lib64/ruby/gems/2.4.0/gems/mutant-0.8.13/lib/mutant/env.rb:44:in `run_mutation_tests'
from /usr/lib64/ruby/gems/2.4.0/gems/mutant-0.8.13/lib/mutant/env.rb:25:in `kill'
from /usr/lib64/ruby/gems/2.4.0/gems/mutant-0.8.13/lib/mutant/parallel/worker.rb:60:in `call'
from /usr/lib64/ruby/gems/2.4.0/gems/mutant-0.8.13/lib/mutant/parallel/worker.rb:60:in `handle_job'
from /usr/lib64/ruby/gems/2.4.0/gems/mutant-0.8.13/lib/mutant/parallel/worker.rb:45:in `handle'
from /usr/lib64/ruby/gems/2.4.0/gems/mutant-0.8.13/lib/mutant/parallel/worker.rb:31:in `run'
from /usr/lib64/ruby/gems/2.4.0/gems/mutant-0.8.13/lib/mutant/parallel/worker.rb:17:in `run'
from /usr/lib64/ruby/gems/2.4.0/gems/mutant-0.8.13/lib/mutant/parallel/master.rb:43:in `block (2 levels) in run'
from /usr/lib64/ruby/gems/2.4.0/gems/mutant-0.8.13/lib/mutant/actor/env.rb:14:in `block in spawn'
/usr/lib64/ruby/gems/2.4.0/gems/mutant-rspec-0.8.13/lib/mutant/integration/rspec.rb:124:in `parse_expression': undefined method `captures' for nil:NilClass (NoMethodError)
Did you mean? capture
from /usr/lib64/ruby/gems/2.4.0/gems/mutant-rspec-0.8.13/lib/mutant/integration/rspec.rb:109:in `parse_example'
from /usr/lib64/ruby/gems/2.4.0/gems/mutant-rspec-0.8.13/lib/mutant/integration/rspec.rb:88:in `block in all_tests_index'
from /usr/lib64/ruby/gems/2.4.0/gems/mutant-rspec-0.8.13/lib/mutant/integration/rspec.rb:87:in `each'
from /usr/lib64/ruby/gems/2.4.0/gems/mutant-rspec-0.8.13/lib/mutant/integration/rspec.rb:87:in `each_with_index'
from /usr/lib64/ruby/gems/2.4.0/gems/mutant-rspec-0.8.13/lib/mutant/integration/rspec.rb:87:in `each_with_object'
from /usr/lib64/ruby/gems/2.4.0/gems/mutant-rspec-0.8.13/lib/mutant/integration/rspec.rb:87:in `all_tests_index'
from /usr/lib64/ruby/gems/2.4.0/gems/memoizable-0.4.2/lib/memoizable/method_builder.rb:117:in `call'
from /usr/lib64/ruby/gems/2.4.0/gems/memoizable-0.4.2/lib/memoizable/method_builder.rb:117:in `block (3 levels) in create_memoized_method'
from /usr/lib64/ruby/gems/2.4.0/gems/memoizable-0.4.2/lib/memoizable/memory.rb:63:in `block (3 levels) in fetch'
from /usr/lib64/ruby/gems/2.4.0/gems/thread_safe-0.3.6/lib/thread_safe/cache.rb:56:in `fetch'
from /usr/lib64/ruby/gems/2.4.0/gems/memoizable-0.4.2/lib/memoizable/memory.rb:62:in `block (2 levels) in fetch'
from /usr/lib64/ruby/2.4.0/monitor.rb:214:in `mon_synchronize'
from /usr/lib64/ruby/gems/2.4.0/gems/memoizable-0.4.2/lib/memoizable/memory.rb:61:in `block in fetch'
from /usr/lib64/ruby/gems/2.4.0/gems/thread_safe-0.3.6/lib/thread_safe/cache.rb:56:in `fetch'
from /usr/lib64/ruby/gems/2.4.0/gems/memoizable-0.4.2/lib/memoizable/memory.rb:60:in `fetch'
from /usr/lib64/ruby/gems/2.4.0/gems/memoizable-0.4.2/lib/memoizable/method_builder.rb:116:in `block (2 levels) in create_memoized_method'
from /usr/lib64/ruby/gems/2.4.0/gems/mutant-rspec-0.8.13/lib/mutant/integration/rspec.rb:77:in `all_tests'
from /usr/lib64/ruby/gems/2.4.0/gems/memoizable-0.4.2/lib/memoizable/method_builder.rb:117:in `call'
from /usr/lib64/ruby/gems/2.4.0/gems/memoizable-0.4.2/lib/memoizable/method_builder.rb:117:in `block (3 levels) in create_memoized_method'
from /usr/lib64/ruby/gems/2.4.0/gems/memoizable-0.4.2/lib/memoizable/memory.rb:63:in `block (3 levels) in fetch'
from /usr/lib64/ruby/gems/2.4.0/gems/thread_safe-0.3.6/lib/thread_safe/cache.rb:56:in `fetch'
from /usr/lib64/ruby/gems/2.4.0/gems/memoizable-0.4.2/lib/memoizable/memory.rb:62:in `block (2 levels) in fetch'
from /usr/lib64/ruby/2.4.0/monitor.rb:214:in `mon_synchronize'
from /usr/lib64/ruby/gems/2.4.0/gems/memoizable-0.4.2/lib/memoizable/memory.rb:61:in `block in fetch'
from /usr/lib64/ruby/gems/2.4.0/gems/thread_safe-0.3.6/lib/thread_safe/cache.rb:56:in `fetch'
from /usr/lib64/ruby/gems/2.4.0/gems/memoizable-0.4.2/lib/memoizable/memory.rb:60:in `fetch'
from /usr/lib64/ruby/gems/2.4.0/gems/memoizable-0.4.2/lib/memoizable/method_builder.rb:116:in `block (2 levels) in create_memoized_method'
from /usr/lib64/ruby/gems/2.4.0/gems/mutant-0.8.13/lib/mutant/selector/expression.rb:14:in `block in call'
from /usr/lib64/ruby/gems/2.4.0/gems/mutant-0.8.13/lib/mutant/selector/expression.rb:13:in `each'
from /usr/lib64/ruby/gems/2.4.0/gems/mutant-0.8.13/lib/mutant/selector/expression.rb:13:in `call'
from /usr/lib64/ruby/gems/2.4.0/gems/mutant-0.8.13/lib/mutant/env.rb:44:in `run_mutation_tests'
from /usr/lib64/ruby/gems/2.4.0/gems/mutant-0.8.13/lib/mutant/env.rb:25:in `kill'
from /usr/lib64/ruby/gems/2.4.0/gems/mutant-0.8.13/lib/mutant/parallel/worker.rb:60:in `call'
from /usr/lib64/ruby/gems/2.4.0/gems/mutant-0.8.13/lib/mutant/parallel/worker.rb:60:in `handle_job'
from /usr/lib64/ruby/gems/2.4.0/gems/mutant-0.8.13/lib/mutant/parallel/worker.rb:45:in `handle'
from /usr/lib64/ruby/gems/2.4.0/gems/mutant-0.8.13/lib/mutant/parallel/worker.rb:31:in `run'
from /usr/lib64/ruby/gems/2.4.0/gems/mutant-0.8.13/lib/mutant/parallel/worker.rb:17:in `run'
from /usr/lib64/ruby/gems/2.4.0/gems/mutant-0.8.13/lib/mutant/parallel/master.rb:43:in `block (2 levels) in run'
from /usr/lib64/ruby/gems/2.4.0/gems/mutant-0.8.13/lib/mutant/actor/env.rb:14:in `block in spawn'
Am I doing something wrong or this is a bug?
@Ana06 Looks like both, you are doing something wrong and there is a bug!
What you likely do wrong is not forcing the constant to exist, its hard to tell what you are exactly doing without seeing the repo.
But there is a bug in the rspec integration that should not crash on non expected rspec descriptions.
Is there a chance you can publish a minimal reproduction of this?
I can send you the repo :wink: Here is the project with the gem on it already: https://github.com/Ana06/open-build-service/tree/mutants
@Ana06 I've looked at this repository, and found the api subproject.
Running the specs requires setup I do not have the time to do. Do not want to setup mysql right now.
But I've pushed a branch (without specs yet) that may get you past the obvious mutant bug. Can you try your project against this PRs branch? https://github.com/mbj/mutant/pull/716
@mbj
@Ana06 I've looked at this repository, and found the api subproject
Sorry, I should have told you that the Rails project is in the api directory :confounded:
But I've pushed a branch (without specs yet) that may get you past the obvious mutant bug. Can you try your project against this PRs branch? #716
It works! :tada: Thank you so much for taking the time to look at the repository and to fix the bug! :wink:
@Ana06 I'll try to get this done properly and have it in a release.
OT: This change does just fix a crash where mutant could NOT find a good test for a mutation, and while it let you get past the crash, it shows your project does not (yet) to be well aligned with mutant test selection criteria and mutation testing will be very low performance.