Coder Social home page Coder Social logo

lspec's Introduction

LSpec

LSpec is a Test-Driven Development tool for the Lasso language that gets its inspiration from RSpec.

Terminology

Expectation
Used to define expected outcomes within a test. (Each [expect] statement)
Test
A grouping of expectations and related code to test specific functionality. (Each [it] block.)
Test Group
A grouping of related tests. (Each [describe] block.)
Test Suite
Compilation of all the test groups.

Installation

Pre-compiled Libraries

  1. Click the "Downloads" menu option at the top of this page.
  2. Choose the proper download for your platform
  3. Decompress the files and move lspec to $LASSO9_HOME/bin/ and lspec.so or lspec.dylib into $LASSO9_HOME/LassoLibraries/

Compile From Source

$> cd where/you/want/the/source/installed/
$> git clone https://bitbucket.org/bfad/lspec.git
$> cd lspec
$> make
$> make install

Note: If you're compiling on Mac OS X, you'll need the 10.5 SDK installed. You can follow the instructions here to restore the 10.5 SDK to Xcode 4.

Set Your Path

The installation instructions above specified that the lspec command utility be installed into $LASSO9_HOME/bin/. You may want to add that to your shell's PATH so you can just type lspec and not $LASSO9_HOME/bin/lspec from the command-line. (Check your shell's documentation to determine how to setup your PATH environment variable.)

Example

First, create a file named zoo.spec.inc and write a test describing functionality you wish you had. (It's important that the test file ends with the extension '.spec.inc'.)

describe('Zoo') => {
    describe('addAnimal') => {
        it('inserts an animal into the zoo and increases numberOfAnimals by 1') => {
            local(menagerie) = zoo
            local(num_animals_start) = #menagerie->numberOfAnimals
            local(num_animals_end)
            
            #menagerie->addAnimal(animal('Rhino'))
            #num_animals_end = #menagerie->numberOfAnimals
            
            expect(#menagerie->hasA('Rhino'))
            expect(#num_animals_end == 1 + #num_animals_start)
        }
    }
}

Then run the test and watch it fail.

$> lspec zoo.spec.inc
F

Failures:

    1) Zoo addAnimal inserts an animal into the zoo and increases numberOfAnimals by 1
       Failure/Error: Unexpcted Error!
           Error Code: -9948
            Error Msg: Definition Not Found: zoo()
       # 3:9 /Path/To/zoo.spec.inc

Finished in 0.206136 seconds
1 test, 1 failure

Now add the following code to the beginning of zoo.spec.inc. (Usually you would keep the tests in separate files and have them first include the code you are testing.)

define zoo => type {
    data private animals = array

    public hasA(name::string) => {
        with animal in .animals do {
            #name == #animal->name?
                return true
        }
        return false
    }

    public addAnimal(creature::animal) => {
        .'animals'->insert(#creature)
    }

    public numberOfAnimals => .animals->size
}

define animal => type {
    data private name::string
    public name => .'name'

    public onCreate(name::string) => {
        .'name' = #name
    }
}

With this code in place, re-run the test and watch it pass.

$> lspec zoo.spec.inc
.

Finished in 0.147116 seconds
1 test, 0 failures

License

Copyright 2011 Bradley Lindsay

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.

lspec's People

Contributors

bfad avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

lspec's Issues

Minor glitch in display

Minor observation. When I run a test it does not end with a new line. Thus it will look like this:

jolle$ lspec tests/zoo.spec.inc
.

Finished in 0.103695 seconds
1 test, 0 failuresjolle:lasso jolle$

That is a bit confusing and not as pretty as could be.

expect fails on integers

I get this error
Definition Not Found: expect(integer)
when running this test
expect(#msgArray -> isa(::array))

msgArray -> isa(::array) will return 1 when it's true.

Run Time Is Off

The reported time it takes is too long. I used the unix time command to time the lspec command test suite when it only had one test, and this is the output:

$> time lasso9 spec/command/lspec.spec.inc
.

Finished in 1.428784 seconds
1 test, 0 failures

real    0m1.228s
user    0m1.213s
sys     0m0.041s

As you can see, the real time is shorter than the run time!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.