expectations 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -30,6 +30,14 @@ You can download expectations from here[http://rubyforge.org/projects/expectatio
30
30
 
31
31
  You may use, copy and redistribute this library under the same terms as Ruby itself (see http://www.ruby-lang.org/en/LICENSE.txt).
32
32
 
33
+ == TextMate
34
+
35
+ The following code can be used as a new command in TextMate for running an individual expectation.
36
+
37
+ export LINE="$TM_LINE_NUMBER"
38
+ export RUBYLIB="$TM_BUNDLE_SUPPORT/RubyMate${RUBYLIB:+:$RUBYLIB}"
39
+ "${TM_RUBY:-ruby}" -- "$TM_BUNDLE_SUPPORT/RubyMate/run_script.rb"
40
+
33
41
  == Usage
34
42
 
35
43
  expectations can be used for state based and behavior based testing.
@@ -58,7 +66,7 @@ expectations can be used for state based and behavior based testing.
58
66
  expect Object.to_receive(:deal) do
59
67
  Object.deal
60
68
  end
61
-
69
+
62
70
  end
63
71
 
64
72
  == Contributors
data/lib/expectations.rb CHANGED
@@ -2,7 +2,11 @@ module Expectations
2
2
  end
3
3
 
4
4
  def Expectations(&block)
5
- Expectations::SuiteRunner.instance.suite_eval &block
5
+ begin
6
+ Expectations::SuiteRunner.instance.suite_eval &block
7
+ rescue
8
+ Expectations::SuiteRunner.instance.do_not_run
9
+ end
6
10
  end
7
11
 
8
12
  require 'rubygems'
@@ -1,6 +1,4 @@
1
1
  module Expectations::BehaviorBasedExpectation
2
- include Mocha::Standalone
3
-
4
2
  def execute
5
3
  begin
6
4
  mocha_setup
@@ -1,5 +1,5 @@
1
1
  class Expectations::Expectation
2
-
2
+ include Mocha::Standalone
3
3
  attr_accessor :expected, :block, :file, :line, :actual
4
4
 
5
5
  def initialize(expected, &block)
@@ -1,8 +1,8 @@
1
1
  class Expectations::MockRecorder
2
2
  attr_accessor :target
3
- def initialize(target, method)
3
+ def initialize(target, method=nil)
4
4
  self.target = target
5
- events << MockEvent.new(:expects, [method])
5
+ events << MockEvent.new(:expects, [method]) unless method.nil?
6
6
  end
7
7
 
8
8
  def events
@@ -10,6 +10,7 @@ class Expectations::MockRecorder
10
10
  end
11
11
 
12
12
  def method_missing(method, *args)
13
+ super if events.empty?
13
14
  events << MockEvent.new(method, args)
14
15
  self
15
16
  end
@@ -1,7 +1,8 @@
1
1
  module Expectations::StateBasedExpectation
2
2
  def execute
3
3
  begin
4
- self.actual = block.call
4
+ mocha_setup
5
+ self.actual = instance_eval &block
5
6
  return self.extend(Expectations::Results::Fulfilled) if expected == actual
6
7
  rescue Exception => ex
7
8
  return self.extend(Expectations::Results::Fulfilled) if expected == ex.class
@@ -9,6 +10,8 @@ module Expectations::StateBasedExpectation
9
10
  self.exception = ex
10
11
  self.message = "expected: <#{expected.inspect}> got: <#{ex.class.inspect}>" if expected.is_a?(Class) && expected < StandardError
11
12
  return self
13
+ ensure
14
+ mocha_teardown
12
15
  end
13
16
  self.extend(Expectations::Results::StateBasedFailure)
14
17
  end
@@ -1,7 +1,7 @@
1
1
  class Expectations::Suite
2
2
 
3
3
  def mock
4
- Mocha::Mock.new
4
+ Expectations::MockRecorder.new(self)
5
5
  end
6
6
 
7
7
  def execute(out=STDOUT)
@@ -10,6 +10,7 @@ class Expectations::Suite
10
10
  ENV["LINE"].nil? ? run_all(suite_result) : run_one(suite_result)
11
11
  end
12
12
  suite_result.print_results(benchmark)
13
+ suite_result.write_xml(ENV["JUnitXmlPath"]) unless ENV["JUnitXmlPath"].nil?
13
14
  suite_result.result
14
15
  end
15
16
 
@@ -1,14 +1,19 @@
1
1
  class Expectations::SuiteRunner
2
2
  include Singleton
3
- attr_accessor :suite
3
+ attr_accessor :suite, :runnable
4
4
 
5
5
  def initialize
6
6
  self.suite = Expectations::Suite.new
7
+ self.runnable = true
7
8
  at_exit do
8
- exit 1 unless suite.execute
9
+ exit 1 unless runnable && suite.execute
9
10
  end
10
11
  end
11
12
 
13
+ def do_not_run
14
+ self.runnable = false
15
+ end
16
+
12
17
  def suite_eval(&block)
13
18
  self.suite.instance_eval &block
14
19
  end
data/rakefile.rb CHANGED
@@ -41,7 +41,7 @@ specification = Gem::Specification.new do |s|
41
41
  expect NoMethodError do
42
42
  Object.invalid_method_call
43
43
  end."
44
- s.version = "0.0.8"
44
+ s.version = "0.0.9"
45
45
  s.author = 'Jay Fields'
46
46
  s.description = "A lightweight unit testing framework. Tests (expectations) will be written as follows
47
47
  expect 2 do
@@ -22,5 +22,22 @@ Expectations do
22
22
  expect Object.to_receive(:deal) do
23
23
  Object.deal
24
24
  end
25
-
25
+
26
+ # State based test utilizing a stub
27
+ expect 2 do
28
+ stub(:two => 2).two
29
+ end
30
+
31
+ # State based test utilizing a concrete mock
32
+ expect 2 do
33
+ Object.expects(:bar).returns 2
34
+ Object.bar
35
+ end
36
+
37
+ # Behavior based test utilizing a stub and a concrete mock
38
+ expect 1 do
39
+ Object.expects(:give_me_three).with(3).returns 1
40
+ Object.give_me_three(stub(:three=>3).three)
41
+ end
42
+
26
43
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: expectations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jay Fields
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-01-06 00:00:00 -08:00
12
+ date: 2008-01-07 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15