0.12.6

0.12.5

0.12.4

0.12.3

This works now: should_not("do something") as an alias for denies

You can now pass arguments to asserts, denies, should, and should_not.

context "Playing with hashes" do
    setup do
        { "foo" => "bar" }
    end

    asserts(:[], "foo").equals("bar")
    should(:[], "foo").equals("bar")
    denies(:[], "foo").equals("goo")
    should_not(:[], "foo").equals("goo")
end # Playing with hashes

No tests will run in this situation.

0.12.2

0.12.1

0.12.0

denies("my name") { "Rumplestiltzkin" }.equals("Henry")

0.11.4

Who can argue with porting from rspec to riot? Not me.

describe "My thing" do
  asserts(:size).equals(:small)
end # My thing

The following also works:

context "Another thing is"
  describe "my" do
    asserts_topic.equals("marshmallow") # this test will fail ... because it will ... because it's wrong
  end # my
end # Another thing is

0.11.3

asserts("a number") { 42 }.matches(/\d+/)
# same as
asserts("a number as string") { "42" }.matches(/\d+/)

0.11.2

0.11.1

class MyMiddleware < Riot::ContextMiddleware
  register

  def call(context)
    context.setup { "fooberries" }

    middleware.call(context)

    context.hookup { "furberries" } if context.option(:barns)
  end
end

0.11.0

context "Foo" do
  setup { puts "called second" }
  setup { puts "called third" }
  setup(true) { puts "called first" }
end # Foo

Essentially, these are useful for middlewares. For instance, if you wanted to tell a middleware that was looking for a "transactional" option before running code in a transaction block, you might do this:

context User do
  set :transactional, true
end # User

The middleware might do something with it:

class TransactionalMiddleware < Riot::ContextMiddleware
  register

  def handle?(context) context.option(:transactional) == true; end

  def prepare(context)
    # transactional stuff
  end
end # TransactionalMiddleware

You can call set as many times as you like

context User do
  set :transactional, true
  set :foo, :bar
end

This is something I started building into riot-rails and decided it was useful enough to just put it into riot itself. If, for instance, you wanted to add a setup with some stuff only if the context description was equal to "Your Mom":

class YourMomMiddleware < Riot::ContextMiddleware
  register

  def handle?(context)
    context.description == "Your Mom"
  end

  def prepare(context)
    context.setup do
      "your mom is the topic"
    end
  end
end # YourMomMiddleware

0.10.13

context "Foo" do
  helper(:user) { User.new }
  setup do
    Baz.new(:user => user) # :)
  end
end # Foo
context "Foo.bar" do
  asserts("baz is called") do
    mock(Foo).baz
    raise RuntimeError.new("oh noes")
  end
end

would previously return [:fail, "baz() Called 0 times. Expected 1 times."], and will now correctly return [:error, #]

foo_context = context(Foo) {}
bar_context = foo_context.context(Bar) {}
bar_context.description
=> Bar
bar_context.detailed_description
=> "Foo Bar"
context "foo" do
  setup { "bar" }
  asserts_topic.kind_of(String)
  asserts("topic").kind_of(String) # Will fail since block returns `false`
  asserts("topic").equals(false) # Will actually pass :)
end

0.10.12

# teststrap.rb
require 'riot'
require 'riot/rr'

# your-test.rb
context "foo" do
  asserts("failure due to not calling hello") { mock!.hello {"world"} } # actually fails
end
def evaluate(actual, expected)
  # ...
  expected == actual pass(new_message.received(expected)) ? fail(expected(expected).not(actual))
  # ...
end
Riot::Context.new("Hi", nil) {}.parent.class
=> Riot::RootContext

0.10.11

asserts_topic.exists
asserts_topic("some kind of description").exists
setup { User.new(:funny? => false) }
asserts(:funny?).not!
context "yo mama" do
  setup { YoMama.new }
  # ...
  context "is cool" do
    hookup { topic.do_something_involving_state }
    asserts_topic.kind_of?(YoMama)
  end
end
Riot.alone!
Riot.run

This will still print output unless you also Riot.silently!

0.10.10

def evaluate(actual, *expectings)
  1 == 1 ? pass("1 does equal 1") : fail("1 does not equal 1 in this universe")
end
setup { "foo" }
asserts(:upcase).equals("FOO")
module My
  class CustomThingAssertion < Riot::AssertionMacro
    register :custom_thing
    expects_exception!

    def evaluate(actual, *expectings)
      # ...
    end
  end

  Riot::Assertion.register_macro :custom_thing, CustomThingAssertion
end
class SomeNewReporter < IOReporter
  def pass
    puts "I PASSED"
  end

  def fail
    print "F"
  end
  # ...
end

0.10.9 and before

See the commit log: http://github.com/thumblemonks/riot/commits/master