/jspec

An RSpec like micro framework for java language.

Primary LanguageJava

License

JSpec

An RSpec like micro framework for java (Still under construction!).

Features

  • Describe your tests as RSpec way.
  • Run a JSpec specification as a JUnit test from your favorite IDE (Idea/Eclipse).
  • Run tests with gradle as rspec --format=doc way.
  • Use hamcrest assertions.

Modules

  • jspec-core: The jspec framework.
  • jspec-plugin: The spec gradle plugin. This allow run tests from console.
  • jspec-test: A sample test module.

Install

Step 1: Clone the project.

git clone https://github.com/adrianmarino/jspec.git

Step 2: Install jspec core & gradle plugin to local maven repository.

gradle clean install -PexcludeTest

Step 3: Add a jspec shortcut command.

echo "alias jspec='gradle -q jspec'" >> ~/.bashrc

Step 4: Run sample StackSpec to check that all it working.

jspec

You should view the next output:

Use

From gradle

Step 1: Add plugin to build.gradle.

apply plugin: 'jspec'

buildscript {
	repositories {
		mavenLocal()
		mavenCentral()
	}
	dependencies {
		classpath 'ar.com.nonosoft:jspec-plugin:0.0.1'
	}
}

Step 2: Describe a spec.

public class StackSpec extends Spec<Stack> {{
	describe(d -> {
		d.let("one", 1).let("two", 2);

		d.describe(".new", ()-> {
			d.context("when create an empty stack", c -> {
                c.subject(() -> new Stack<Integer>() {{ push(c.get("one")); }});
				c.it("is empty", expect -> expect.that(c.subject().isEmpty(), is(true)));
			});
		});

		d.describe("#push", ()-> {
			d.context("when push new element onto top", c -> {
				c.subject(new Stack<Integer>() {{ push(c.get("one")); }});

				c.it("has an element onto top", expect -> {
					expect.that(c.subject().get(0), is(equalTo(c.get("one"))));
				});
			});
		});

		d.describe("#pop", ()-> {
			d.context("when pop the last element", (c) -> {
				c.subject(new Stack<Integer>() {{ push(c.get("one")); push(c.get("two")); }});

				c.it("element is the last pushed", expect -> {
					expect.that(c.subject().pop(), is(equalTo(c.get("two"))));
				});
			});
		});

		d.context("when use an spring context", (c)-> {
			c.springContext(SampleContext.class);
			c.it("has a hello string", expect -> {
                expect.that(c.bean("testString"), is(equalTo("Hello")));
            });
		});
		
		d.it("is a pending It");
		
		d.xit("is a pending It", (expect) -> expect.that(true, is(false)));
	});
}}

Step 3: Run all specs.

jspec

Also could run specs in a particular package.

jspec -Ppkg=ar.com.nonosoft.test

Step 4: Run from:


Intellij Idea


Eclipse

Specification Guide

Coming soon! (Better Specs documentation).

TODO

  • Many tests.
  • Spec maven plugin.
  • let!
  • Unique IDE test description.