Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

first steps in expectations

  • Loading branch information...
commit bbcc3b68e02ab45f2ac1bc123516d7ecd8e4b770 1 parent 2f768f1
Josep M. Bach authored
2  Gemfile.lock
View
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- stendhal (0.0.1)
+ stendhal (0.1.0)
GEM
remote: http://rubygems.org/
22 features/examples.feature
View
@@ -1,10 +1,10 @@
Feature: Examples and example groups
- Spec-ish Domain Specific Language
+ RSpec-ish Domain Specific Language
Scenario: declare an example
- Given a directory named "rspec_project"
- When I cd to "rspec_project"
+ Given a directory named "stendhal_project"
+ When I cd to "stendhal_project"
Given a file named "sample_spec.rb" with:
"""
describe "something" do
@@ -18,8 +18,8 @@ Feature: Examples and example groups
And the output should contain "1 example, 0 failures"
Scenario: declare a failing example
- Given a directory named "rspec_project"
- When I cd to "rspec_project"
+ Given a directory named "stendhal_project"
+ When I cd to "stendhal_project"
Given a file named "sample_spec.rb" with:
"""
describe "something" do
@@ -34,8 +34,8 @@ Feature: Examples and example groups
And the output should contain "1 example, 1 failure"
Scenario: declare a pending example
- Given a directory named "rspec_project"
- When I cd to "rspec_project"
+ Given a directory named "stendhal_project"
+ When I cd to "stendhal_project"
Given a file named "sample_spec.rb" with:
"""
describe "something" do
@@ -50,8 +50,8 @@ Feature: Examples and example groups
And the output should contain "1 example, 0 failures, 1 pending"
Scenario: declare an example in nested groups
- Given a directory named "rspec_project"
- When I cd to "rspec_project"
+ Given a directory named "stendhal_project"
+ When I cd to "stendhal_project"
Given a file named "sample_spec.rb" with:
"""
describe "something" do
@@ -70,8 +70,8 @@ Feature: Examples and example groups
And the output should contain "1 example, 0 failures"
Scenario: many examples in different example groups
- Given a directory named "rspec_project"
- When I cd to "rspec_project"
+ Given a directory named "stendhal_project"
+ When I cd to "stendhal_project"
Given a file named "sample_spec.rb" with:
"""
describe "something" do
56 features/expectations.feature
View
@@ -0,0 +1,56 @@
+Feature: Expectations
+
+ Stendhal comes with some built-in expectations.
+
+ Scenario: equality expectations
+ Given a directory named "stendhal_project"
+ When I cd to "stendhal_project"
+ Given a file named "sample_spec.rb" with:
+ """
+ describe "something" do
+ it "does something" do
+
+ (3 + 4).should == 7
+ 6.should_not == 7
+
+ end
+ end
+ """
+ When I run "stendhal sample_spec.rb"
+ Then the exit status should be 0
+ And the output should contain "1 example, 0 failures"
+
+ Scenario: identity expectations
+ Given a directory named "stendhal_project"
+ When I cd to "stendhal_project"
+ Given a file named "sample_spec.rb" with:
+ """
+ describe "something" do
+ it "does something" do
+
+ 6.should be_a(Fixnum)
+
+ end
+ end
+ """
+ When I run "stendhal sample_spec.rb"
+ Then the exit status should be 0
+ And the output should contain "1 example, 0 failures"
+
+ Scenario: predicate expectations
+ Given a directory named "stendhal_project"
+ When I cd to "stendhal_project"
+ Given a file named "sample_spec.rb" with:
+ """
+ describe "something" do
+ it "does something" do
+
+ str = "String".freeze
+ str.should be_frozen
+
+ end
+ end
+ """
+ When I run "stendhal sample_spec.rb"
+ Then the exit status should be 0
+ And the output should contain "1 example, 0 failures"
4 lib/stendhal.rb
View
@@ -1,4 +1,6 @@
-require 'stendhal/assertions'
+require 'stendhal/exceptions'
+require 'stendhal/expectations'
+require 'stendhal/matchers'
require 'stendhal/example'
require 'stendhal/example_group'
12 lib/stendhal/assertions.rb
View
@@ -1,12 +0,0 @@
-module Stendhal
- module Assertions
- def assert test, msg = nil
- msg ||= "Failed assertion, no message given."
- unless test then
- raise AssertionFailed, msg
- end
- true
- end
- end
- class AssertionFailed < Exception; end
-end
2  lib/stendhal/dsl.rb
View
@@ -1,5 +1,6 @@
module Stendhal
module DSL
+
module Example
def it(*args,&blk)
self.add_example Stendhal::Example.new(*args,&blk)
@@ -14,6 +15,7 @@ def pending(*args,&blk)
self.add_example Stendhal::Example.new(*args,options,&blk)
end
end
+
end
end
2  lib/stendhal/example.rb
View
@@ -1,6 +1,6 @@
module Stendhal
class Example
- include Assertions
+ include Matchers
@@examples = []
5 lib/stendhal/exceptions.rb
View
@@ -0,0 +1,5 @@
+module Stendhal
+ module Exceptions
+ class ExpectationNotMet < StandardError; end
+ end
+end
7 lib/stendhal/expectations.rb
View
@@ -0,0 +1,7 @@
+module Stendhal
+ module Expectations
+ class EqualityExpectation; end
+ class KindExpectation; end
+ class PredicateExpectation; end
+ end
+end
18 lib/stendhal/matchers.rb
View
@@ -0,0 +1,18 @@
+module Stendhal
+ module Matchers
+ def ==(other)
+ Stendhal::Expectations::EqualityExpectation.new(other)
+ end
+ def eq(other)
+ Stendhal::Expectations::EqualityExpectation.new(other)
+ end
+ def be_a(kind)
+ Stendhal::Expectations::KindExpectation.new(kind)
+ end
+ def method_missing(m,*args)
+ if m.to_s =~ /be_(\w+)/
+ Stendhal::Expectations::PredicateExpectation.new(($1 + '?').to_sym)
+ end
+ end
+ end
+end
29 spec/stendhal/assertions_spec.rb
View
@@ -1,29 +0,0 @@
-require 'spec_helper'
-
-class MyClass
- include Stendhal::Assertions
-end
-
-module Stendhal
- describe Assertions do
-
- subject { MyClass.new }
-
- describe "#assert" do
-
- it "does nothing if asserted expression returns true" do
- subject.assert true
- end
-
- it "raises an AssertionFailed exception otherwise" do
- expect { subject.assert false }.to raise_error(AssertionFailed)
- end
-
- it "yields a given message for the error" do
- expect { subject.assert false, "softwared!" }.to raise_error(AssertionFailed, "softwared!")
- end
-
- end
-
- end
-end
34 spec/stendhal/matchers_spec.rb
View
@@ -0,0 +1,34 @@
+require 'spec_helper'
+
+class MyClass
+ include Stendhal::Matchers
+end
+
+module Stendhal
+ describe "a class with included Matchers" do
+
+ let(:object) { MyClass.new }
+
+ describe "#==" do
+ it 'creates a new equality expectation' do
+ Expectations::EqualityExpectation.should_receive(:new).with(7)
+ object == 7
+ end
+ end
+
+ describe "#be_a" do
+ it 'creates a new kind expectation' do
+ Expectations::KindExpectation.should_receive(:new).with(Fixnum)
+ object.be_a(Fixnum)
+ end
+ end
+
+ describe "#be_whatever" do
+ it 'creates a new predicate expectation' do
+ Expectations::PredicateExpectation.should_receive(:new).with(:frozen?)
+ object.be_frozen
+ end
+ end
+
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.