Skip to content

Commit

Permalink
improved geb example
Browse files Browse the repository at this point in the history
  • Loading branch information
hauner committed Jan 7, 2012
1 parent 2090989 commit 0fa2fa7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 35 deletions.
@@ -1,42 +1,14 @@
/*
* Copyright 2012 Martin Hauner
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import pages.ElementListPage
import pages.ElementNewPage
import pages.ElementShowPage
import grails.plugin.cucumber.Element

this.metaClass.mixin (cucumber.runtime.groovy.Hooks)
this.metaClass.mixin (cucumber.runtime.groovy.EN)


/*
def createElement (String element) {
println "before save"
if (element == 'Gold') {
//new Element (atomicNumber: 79, name: 'Gold', symbol: 'Au').save ()
}
println "after save"
Given (~'^\"([^\"]*)\" already exists$') { String element ->
ElementFactory.createElement (element)
}
*/


//Given (~'^\"([^\"]*)\" already exists$') { String element ->
//createElement (element)
//}

Given (~'^I am in my laboratory$') { ->
to ElementListPage
Expand All @@ -60,5 +32,5 @@ Then (~'^my element list contains \"([^\"]*)\"$') { String element ->
to ElementListPage
assert at (ElementListPage)

page.checkElement (element, 0)
page.checkElementAtRow (element, 0)
}
9 changes: 6 additions & 3 deletions test/projects/geb/test/cucumber/support/env.groovy
Expand Up @@ -7,15 +7,18 @@ this.metaClass.mixin (cucumber.runtime.groovy.EN)

def bindingUpdater

/*
World {
}
*/

Before () {
println "Before Hook"
ElementFactory.clearElements()

bindingUpdater = new BindingUpdater (binding, new Browser ())
bindingUpdater.initialize ()
}

After () {
println "After Hook"

bindingUpdater.remove ()
}
16 changes: 16 additions & 0 deletions test/projects/geb/test/functional/ElementFactory.groovy
@@ -0,0 +1,16 @@
import grails.plugin.cucumber.Element

class ElementFactory {
static void createElement (String element) {
if (element == 'Gold') {
new Element (atomicNumber: 79, name: 'Gold', symbol: 'Au').save ()
}
else {
assert false
}
}

static void clearElements () {
Element.findAll()*.delete (flush: true)
}
}
Expand Up @@ -29,7 +29,7 @@ class ElementListPage extends Page {
}
}

def checkElement (String element, int rowNumber) {
def checkElementAtRow (String element, int rowNumber) {
if (element == "Gold") {
assert row (rowNumber).id.number
assert row (rowNumber).atomicNumber == "79"
Expand Down

0 comments on commit 0fa2fa7

Please sign in to comment.