Skip to content
Skip to breadcrumbs
Skip to header menu
Skip to action menu
Skip to quick search
Quick Search
Browse
Pages
Blog
Labels
Attachments
Mail
Advanced
What’s New
Space Directory
Feed Builder
Keyboard Shortcuts
Confluence Gadgets
Log In
Dashboard
Groovy
Copy Page
You are not logged in. Any changes you make will be marked as
anonymous
. You may want to
Log In
if you already have an account. You can also
Sign Up
for a new account.
This page is being edited by
.
Paragraph
Paragraph
Heading 1
Heading 2
Heading 3
Heading 4
Heading 5
Heading 6
Preformatted
Quote
Bold
Italic
Underline
More colours
Strikethrough
Subscript
Superscript
Monospace
Clear Formatting
Bullet list
Numbered list
Outdent
Indent
Align left
Align center
Align right
Link
Table
Insert
Insert Content
Image
Link
Attachment
Symbol
Emoticon
Wiki Markup
Horizontal rule
tinymce.confluence.insert_menu.macro_desc
Info
JIRA Issue
Status
Gallery
Tasklist
Table of Contents
Other Macros
Page Layout
No Layout
Two column (simple)
Two column (simple, left sidebar)
Two column (simple, right sidebar)
Three column (simple)
Two column
Two column (left sidebar)
Two column (right sidebar)
Three column
Three column (left and right sidebars)
Undo
Redo
Find/Replace
Keyboard Shortcuts Help
<p><a href="http://codeforfun.wordpress.com/2007/04/09/gspec-for-java-bdd/">GSpec</a> is an evolving framework to allow you to apply a <a href="http://en.wikipedia.org/wiki/Behavior_driven_development">BDD</a> style of programming when using Groovy. The sections below illustrate using GSpec for the examples from <a class="confluence-link" href="/display/GROOVY/Using+Testing+Frameworks+with+Groovy" data-linked-resource-id="67695" data-linked-resource-type="page" data-linked-resource-default-alias="Using Testing Frameworks with Groovy" data-base-url="http://docs.codehaus.org">Using Testing Frameworks with Groovy</a>.</p> <h2>The Stack Example</h2> <p>Here is how you might test the <a class="confluence-link" href="/display/GROOVY/Using+Testing+Frameworks+with+Groovy#UsingTestingFrameworkswithGroovy-AStackExample" data-anchor="AStackExample" data-linked-resource-id="67695" data-linked-resource-type="page" data-linked-resource-default-alias="Using Testing Frameworks with Groovy#AStackExample" data-base-url="http://docs.codehaus.org">Stack Example</a> with GSpec:</p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> import com.craig.gspec.GSpecBuilderRunner def the = new GSpecBuilderRunner() the.context('A non-empty stack') { initially { the.stack = new FixedStack() ('a'..'c').each { x -> the.stack.push x } the.stack.should_not_be_empty } specify('should return the top item when sent #peek') { the.stack.peek().should_equal 'c' } specify('should NOT remove the top item when sent #peek') { the.stack.peek().should_equal 'c' the.stack.peek().should_equal 'c' } specify('should be unchanged when sent #push then #pop') { the.stack.push 'Anything' the.stack.pop() the.stack.peek().should_equal 'c' } specify('should return the top item when sent #pop') { the.stack.pop().should_equal 'c' the.stack.push 'c' // put it back the way it was } specify('should remove the top item when sent #pop') { the.stack.pop().should_equal 'c' the.stack.pop().should_equal 'b' } specify('should add to the top when sent #push') { the.stack.push 'd' the.stack.peek().should_equal 'd' } } the.context('An empty stack') { initially { the.stack = new FixedStack() the.stack.should_be_empty } specify('should no longer be empty after #push') { the.stack.push 'anything' the.stack.should_not_be_empty } specify('should complain when sent #peek') { // the.stack.peek().should_fail_with StackUnderflowException } specify('should complain when sent #pop') { // the.stack.pop().should_fail_with StackUnderflowException } } the.context('A stack with one item') { initially { the.stack = new FixedStack() the.stack.push 'anything' the.stack.should_not_be_empty } specify('should remain not empty after #peek') { the.stack.peek() the.stack.should_not_be_empty } specify('should become empty after #pop') { the.stack.pop() the.stack.should_be_empty } } the.context('A stack with one item less than capacity') { initially { the.stack = new FixedStack() (1..<FixedStack.MAXSIZE).each { x -> the.stack.push x } the.stack.should_not_be_full } specify('should become full after #push') { the.stack.push 'Anything' the.stack.should_be_full } } the.context('A full stack') { initially { the.stack = new FixedStack() (1..FixedStack.MAXSIZE).each { x -> the.stack.push x } the.stack.should_be_full } specify('should remain full after #peek') { the.stack.peek() the.stack.should_be_full } specify('should no longer be full after #pop') { the.stack.pop() the.stack.should_not_be_full } specify('should complain on #push') { // the.stack.push('Anything').should_fail_with StackOverflowException } } </pre></td></tr></table> <h2>The Item Storer Example</h2> <p>Here is how you might integration test the <a class="confluence-link" href="/display/GROOVY/Using+Testing+Frameworks+with+Groovy#UsingTestingFrameworkswithGroovy-AnItemStorerExample" data-anchor="AnItemStorerExample" data-linked-resource-id="67695" data-linked-resource-type="page" data-linked-resource-default-alias="Using Testing Frameworks with Groovy#AnItemStorerExample" data-base-url="http://docs.codehaus.org">Item Storer Example</a> with GSpec:</p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> import com.craig.gspec.GSpecBuilderRunner def checkPersistAndReverse(storer, orig, reversed){ storer.put orig storer.get().should_equal orig storer.getReverse().should_equal reversed } def the = new GSpecBuilderRunner() the.context('A new storer') { initially() { the.storer = new Storer() } specify('Should persist and reverse strings') { checkPersistAndReverse the.storer, 'hello', 'olleh' } specify('Should persist and reverse numbers') { checkPersistAndReverse the.storer, 123.456, -123.456 } specify('Should persist and reverse lists') { checkPersistAndReverse the.storer, [1, 3, 5], [5, 3, 1] } } </pre></td></tr></table>
Please type the word appearing in the picture.
Attachments
Labels
Location
Watch this page
< Edit
Preview >
Loading…
Save
Cancel
Next hint
search
attachments
weblink
advanced