spockframework / spockframework/spock

Improve spy error message when constructor args dont match

Open
#399 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Module-Core Type-Defect
Dominant language
Java
Stars
3.6k
Forks
483
PR merge metrics
No merged PRs in 30d

Description

Originally reported on Google Code with ID 277

1. Create some spy like: Spy(Foo, constructorArgs: 'foo')
2. If Foo class does not have any constructor then:

java.lang.ClassCastException
    at java.lang.Class.cast(Class.java:2990)
    at org.spockframework.mock.runtime.MockConfiguration.getOption(MockConfiguration.java:92)
    at org.spockframework.mock.runtime.MockConfiguration.<init>(MockConfiguration.java:46)
    at org.spockframework.lang.SpecInternals.createMock(SpecInternals.java:47)
    at org.spockframework.lang.SpecInternals.createMockImpl(SpecInternals.java:282)
    at org.spockframework.lang.SpecInternals.SpyImpl(SpecInternals.java:171)
    at org.gradle.execution.ExcludedTaskFilteringBuildConfigurationActionTest.$spock_initializeFields(ExcludedTaskFilteringBuildConfigurationActionTest.groovy:30)

Reported by szczepiq on 2012-10-23 09:03:45

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at org.spockframework.mock.runtime.MockConfiguration.java:92 and trace how its constructor options are read from SpecInternals.createMock and SpyImpl. Reproduce a Spy with constructorArgs for a class without a constructor, then make the failure identify the constructor-argument mismatch instead of exposing ClassCastException.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy, java
Domain
testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.