question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Strange "Behavior Spec" behavior

See original GitHub issue

Hello. I tried the last 2.0-SNAPSHOT of kotlinspec (built from this commit). I have next code:

class Test : BehaviorSpec() {
    init {

        Given("test") {

            When("when 1") {
                println("when 1")

                Then("test 1") {
                    println("test 1")
                }
                Then("test 2") {
                    println("test 2")
                }
            }

            When("when 2") {
                println("when 2")

                Then("test 3") {
                    println("test 3")
                }
                Then("test 4") {
                    println("test 4")
                }
            }
        }

    }
}

And there are outputs:


oneInstancePerTest = true     |     oneInstancePerTest = false
when 1                        |     when 1
when 2                        |     when 2
when 1                        |     test 1
when 2                        |     test 2
test 1                        |     test 3
when 1                        |     test 4
when 2 
test 2 
when 1
when 2
test 3
when 1
when 2
test 4

May I am wrong, but I think when block must be running separately just for inner then block:

when 1 -> test 1 -> test 2
when 2 -> test 3 -> test 4

so I can write something like that:

Given(a user try to login)

    When(login was failed)  // mock request, configured via Mockito, returns error, valid for this `when` block
        Then(show error for user)

    When(login is success) // the same mock request returns success, valid for this `when` block
        Then(store auth token)
        Then(redirects user to main)

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
newcatcommented, Jan 18, 2018

The problem might be related to this: When I used interceptors to do setup work before the tests were run, I noticed that code in the Given and When blocks is executed before the spec interceptor is called.

Test setup:

class Test : BehaviorSpec() {
    override fun interceptSpec(context: Spec, spec: () -> Unit) {
        System.out.println("Before Spec")
        spec()
        System.out.println("After Spec")
    }

    init {
        Given("Given") {
            System.out.println("Running Given")
            When("When") {
                System.out.println("Running When")
                Then("Then 1") { System.out.println("Running Then 1") }
                Then("Then 2") { System.out.println("Running Then 2") }
            }
        }
    }
}

Result:

oneInstancePerTest = false
Running Given
Running When
Before Spec
Running Then 1
Running Then 2
After Spec
oneInstancePerTest = true
Running Given
Running When
Before Spec
Running Given
Running When
Running Then 1
Running Given
Running When
Running Then 2
After Spec

IMO the spec interceptor should be called before any code in a given, when or then block is executed.

3reactions
sksamuelcommented, Oct 4, 2017

I think oneInstancePerTest affects things, but isn’t the root cause. I’m looking into it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Strange "Behavior Spec" behavior · Issue #163 - GitHub
Hello. I tried the last 2.0-SNAPSHOT of kotlinspec (built from this commit). I have next code: class Test : BehaviorSpec() { init ...
Read more >
Strange Behavior (1981) - Technical Specifications - IMDb
Technical Specifications ; Runtime, 1 hr 39 min (99 min) 1 hr 45 min (105 min) (New Zealand) 1 hr 27 min (87...
Read more >
ADHD and Disruptive Behavior Disorders - CHADD
Having ADHD along with a coexisting disruptive behavior disorder (ODD/CD) can complicate diagnosis and treatment and also worsen the prognosis.
Read more >
Oppositional Defiant Disorder (ODD): Symptoms & Treatment
Anger and irritability. Argumentative and defiant behavior. · Lose their temper easily. Have frequent outbursts of anger and resentment.
Read more >
Behavioural disorders in children - Better Health Channel
The most common disruptive behaviour disorders include oppositional defiant disorder (ODD), conduct disorder (CD) and attention deficit hyperactivity disorder ( ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found