Skip to content

Instantly share code, notes, and snippets.

@nobeans
Last active December 24, 2015 11:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nobeans/6790221 to your computer and use it in GitHub Desktop.
Save nobeans/6790221 to your computer and use it in GitHub Desktop.
bleisさんの「そろそろPower Assertについてひとこと言っておくか」に纏わるお試しコード http://bleis-tift.hatenablog.com/entry/about-power-assert
import spock.lang.Specification
class MorePowerAssertSpec extends Specification {
def obj1 = new Hoge(name: "あいうえお", value: "ほげ")
def obj2 = new Hoge(name: "あいえお", value: "ほけ")
def obj3 = new Foo(name: "あいうえお", value: "ほげふう", extra: "ふう")
def setup() {
Object.metaClass.p = { delegate.properties.toString() }
}
void "オブジェクトのリッチな比較: 同一インスタンス同士"() {
expect:
obj1.p() == obj1.p()
obj2.p() == obj2.p()
obj3.p() == obj3.p()
}
void "オブジェクトのリッチな比較: 同一クラスの別インスタンス同士"() {
expect:
obj1.p() == obj2.p()
}
void "オブジェクトのリッチな比較: 別クラス同士"() {
expect:
obj1.p() == obj2.p()
}
class Hoge {
def name
def value
}
class Foo {
def name
def value
def extra
}
}
オブジェクトのリッチな比較: 同一クラスの別インスタンス同士(MorePowerAssertSpec)
Condition not satisfied:

obj1.p() == obj2.p()
|    |   |  |    |
|    |   |  |    [value:ほけ, class:class MorePowerAssertSpec$Hoge, name:あいえお]
|    |   |  MorePowerAssertSpec$Hoge@5b2f13ef
|    |   false
|    |   2 differences (98% similarity)
|    |   [value:ほ(げ), class:class MorePowerAssertSpec$Hoge, name:あい(う)えお]
|    |   [value:ほ(け), class:class MorePowerAssertSpec$Hoge, name:あい(-)えお]
|    [value:ほげ, class:class MorePowerAssertSpec$Hoge, name:あいうえお]
MorePowerAssertSpec$Hoge@518c7084

	at MorePowerAssertSpec.groovy:44)


|Running 4 spock tests... 3 of 4
--Output from オブジェクトのリッチな比較: 別クラス同士--
オブジェクトのリッチな比較: 別クラス同士(MorePowerAssertSpec)
Condition not satisfied:

obj1.p() == obj2.p()
|    |   |  |    |
|    |   |  |    [value:ほけ, class:class MorePowerAssertSpec$Hoge, name:あいえお]
|    |   |  MorePowerAssertSpec$Hoge@7a053e2d
|    |   false
|    |   2 differences (98% similarity)
|    |   [value:ほ(げ), class:class MorePowerAssertSpec$Hoge, name:あい(う)えお]
|    |   [value:ほ(け), class:class MorePowerAssertSpec$Hoge, name:あい(-)えお]
|    [value:ほげ, class:class MorePowerAssertSpec$Hoge, name:あいうえお]
MorePowerAssertSpec$Hoge@28c08f61

	at MorePowerAssertSpec.groovy:50)
@nobeans
Copy link
Author

nobeans commented Oct 2, 2013

ちょっとclassがウザいけど、こんな感じかしら

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment