Code Monkey home page Code Monkey logo

vspec's Introduction

VSpec

Build Status

RSpec-like testing framework for the Vala language

This project aims at creating RSpec-like testing framework for the Vala language.

It is at early stage of development but should be sufficient for basic needs and even now should be nicer to use than plain GLib unit tests.

It's being tested on Mac OS X and Vala 0.30.0.

Contributions are welcome!

Sample usage

Spec

using VSpec.Matchers;

public class AbcSpec : VSpec.Spec<MyTestedClass> {
  public override void define() {
    before_each(() => {
      // Before each in that spec
    });

    after_each(() => {
      // After each in that spec
    });

    describe(".something", () => {
      // Equivalent to let in RSpec
      this["lazyvar"] = () => { return "original"; };

      context("if something happened", () => {
        // Test cases will have access to the closest let
        this["lazyvar"] = () => { return "overridden"; };

        before_each(() => {
          // Before each in that context
        });

        after_each(() => {
          // After each in that context
        });

        xit("should do whatever", () => {
          // I am pending spec
        });

        it("should ensure that let is working", () => {
          expect(this["lazyvar"]).to<eq>("overridden");
        });

        it("should fail because of invalid var name", () => {
          expect(this["lazyvar-wrongname"]).to<eq>("123");
        });

        it("should fail because of failed match", () => {
          expect(this["lazyvar"]).to<be_null>();
        });
      });

      it("should throw an arror and keep runner running", () => {
        throw new ThreadError.AGAIN("Abc");
      });

      // Pending context
      xcontext("if something happened", () => {
        it("should print variables ", () => {
          // I won't be called as parent context is pending
        });
      });
    });
  }
}

Runner

public static int main(string[] args) {
  VSpec.add(typeof(AbcSpec));

  VSpec.before_all(() => {
    // Do something before running all specs
  });

  VSpec.after_all(() => {
    // Do something after running all specs
  });

  VSpec.before_each(() => {
    // Do something before each spec
  });

  VSpec.after_each(() => {
    // Do something after each spec
  });


  VSpec.verbose = true; // Print output of all GLib logging functions

  return VSpec.run();
}

Output

Report

Debugging

If you set VSPEC_DEBUG environment variable, VSpec will output additional messages that can be useful while debugging.

Installing

Ubuntu 14.04, 14.10, 15.10 or 16.04

In Ubuntu 14.04, 14.10, 15.10 or 16.04 you can use PPA. Use one of the following command to install packages.

Automatic nightly builds (may be unstable!)

sudo apt-add-repository ppa:vspec/unstable
sudo apt-get update
sudo apt-get install libvspec-1.0-0 libvspec-1.0-dev libvspec-1.0-dbg

Stable builds

Coming soon.

Compiling

Ubuntu/Debian

In Ubuntu/Debian the best way is to create .deb package. You can do this in the following way (tested on Ubuntu 15.10):

  • Install devscripts & equivs: sudo apt-get install devscripts equivs
  • Install build dependencies: sudo mk-build-deps -i -r debian/control
  • Build the package sudo debuild

Other systems

Ensure that automake, C compiler, valac, GLib development library are installed.

  • Run ./configure
  • Run make
  • Run sudo make install

Using in your project

Using with the autotools

In order to satisfy compilation dependencies, you should add:

  • libvspec-1.0 to the pkg-config checks in configure.ac
  • --pkg libvspec-1.0 to the VALAFLAGS in Makefile.am
  • appropriate LD_FLAGS and CFLAGS in Makefile.am

Then just create standard automake TESTS program, and launch runner like in the example above.

Feature status

  • Basic context nesting - DONE
  • Defining variables within context (equivalent to let!) - NOT STARTED
  • Reporting to the console output - DONE
  • Defining lazy-loaded variables within context (equivalent to let) - IN PROGRESS (works but value is not cached)
  • expect syntax - IN PROGRESS (works but you cannot chain multiple matchers and pass delegates)
  • Matchers - IN PROGRESS (works but only eq, be, be_instance_of, be_null, be_true, be_false matchers are available)
  • Shared examples - NOT STARTED
  • Filtering specs in the runner - NOT STARTED
  • Verbose output of the failed specs - NOT STARTED
  • TAP output - NOT STARTED

License

LGPL3

Support & discussions

Please use vspec-users mailing list.

Bug reporting

Please use GitHub issues.

Author

Marcin Lewandowski [email protected]

vspec's People

Contributors

mspanc avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

vspec's Issues

Add TAP output

Add Test Anything Protocol output.

Preferably used automatically when it detects that it is run within make checks, not from raw commandline.

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.