[rspec-users] Does rspec support something like Assumptions in JUnit 4.4?

David Chelimsky dchelimsky at gmail.com
Mon Jun 1 06:58:50 EDT 2009

On Mon, Jun 1, 2009 at 5:33 AM, mortench <mortench at gmail.com> wrote:
> JUnit 4.4+ has a feature called assumptions and I am looking for
> something similar in rspec so that I can express that my examples
> require a specific environment variable to be specified for testing to
> make sense.

There is no explicit support for this, but you could always just say
(taking the example from the page you cited):

def assume_that(expression)
  yield if expression

def verify_that(actual, expected)
  actual.should expected

it "should blah de blah" do
  assume_that(File::SEPARATOR == "/") do
    ensure_that User.new("optimus"), eql("configfiles/optimus.cfg")

I am planning to add support for something like ensure_that (name up
for grabs) in a future version of rspec, but I'd need to think about
assume_that a bit. We're dealing with Ruby here, not Java, and we
don't suffer things like a 'final' keyword that force us to have to
make assumptions like this. Unless we add some additional feedback,
like "such and such example did not run due to faulty assumptions,"
this seems quite dangerous to me. And even with that, it means that CI
servers are going to pass examples that are never actually run.


> About assumptions from the readme (http://junit.sourceforge.net/doc/
> ReleaseNotes4.4.html#assumptions):
> "Ideally, the developer writing a test has control of all of the
> forces that might cause a test to fail. If this isn't immediately
> possible, making dependencies explicit can often improve a design.
> For example, if a test fails when run in a different locale than the
> developer intended, it can be fixed by explicitly passing a locale to
> the domain code.
> However, sometimes this is not desirable or possible.
> It's good to be able to run a test against the code as it is currently
> written, implicit assumptions and all, or to write a test that exposes
> a known bug. For these situations, JUnit now includes the ability to
> express "assumptions":
> "
> /Morten
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users

More information about the rspec-users mailing list