Skip to content

Commit

Permalink
first steps in expectations
Browse files Browse the repository at this point in the history
  • Loading branch information
Josep M. Bach committed Oct 30, 2010
1 parent 2f768f1 commit bbcc3b6
Show file tree
Hide file tree
Showing 12 changed files with 138 additions and 55 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
stendhal (0.0.1)
stendhal (0.1.0)

GEM
remote: http://rubygems.org/
Expand Down
22 changes: 11 additions & 11 deletions features/examples.feature
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
56 changes: 56 additions & 0 deletions features/expectations.feature
Original file line number Diff line number Diff line change
@@ -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 changes: 3 additions & 1 deletion lib/stendhal.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
require 'stendhal/assertions'
require 'stendhal/exceptions'
require 'stendhal/expectations'
require 'stendhal/matchers'
require 'stendhal/example'
require 'stendhal/example_group'

Expand Down
12 changes: 0 additions & 12 deletions lib/stendhal/assertions.rb

This file was deleted.

2 changes: 2 additions & 0 deletions lib/stendhal/dsl.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module Stendhal
module DSL

module Example
def it(*args,&blk)
self.add_example Stendhal::Example.new(*args,&blk)
Expand All @@ -14,6 +15,7 @@ def pending(*args,&blk)
self.add_example Stendhal::Example.new(*args,options,&blk)
end
end

end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/stendhal/example.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Stendhal
class Example
include Assertions
include Matchers

@@examples = []

Expand Down
5 changes: 5 additions & 0 deletions lib/stendhal/exceptions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Stendhal
module Exceptions
class ExpectationNotMet < StandardError; end
end
end
7 changes: 7 additions & 0 deletions lib/stendhal/expectations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Stendhal
module Expectations
class EqualityExpectation; end
class KindExpectation; end
class PredicateExpectation; end
end
end
18 changes: 18 additions & 0 deletions lib/stendhal/matchers.rb
Original file line number Diff line number Diff line change
@@ -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 changes: 0 additions & 29 deletions spec/stendhal/assertions_spec.rb

This file was deleted.

34 changes: 34 additions & 0 deletions spec/stendhal/matchers_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit bbcc3b6

Please sign in to comment.