expectations 1.2.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README CHANGED
@@ -1,13 +1,15 @@
1
1
  = expectations
2
2
 
3
- expectations is a lightweight unit testing framework. Tests (expectations) can be written as follows
3
+ expectations is a lightweight unit testing framework. Tests (expectations) can be written as follows
4
4
 
5
- expect 2 do
6
- 1 + 1
7
- end
5
+ expect 2 do
6
+ 1 + 1
7
+ end
8
8
 
9
- expect NoMethodError do
10
- Object.invalid_method_call
9
+ expect(1 + 1) == 2
10
+
11
+ expect NoMethodError do
12
+ Object.invalid_method_call
11
13
  end.
12
14
 
13
15
  expectations is designed to encourage unit testing best practices such as
@@ -16,9 +18,12 @@ expectations is designed to encourage unit testing best practices such as
16
18
  - provide one syntax for setting up state based or behavior based expectation
17
19
  - focus on readability by providing no mechanism for describing an expectation other than the code in the expectation.
18
20
 
21
+ Works with ruby1.9.1, patches for 1.8 are welcome.
22
+
19
23
  Mocking is done utilizing Mocha[http://mocha.rubyforge.org]
20
24
 
21
25
  by {Jay Fields}[http://blog.jayfields.com]
26
+ maintained by {Holger Kohnen}[http://holgerkohnen.de]
22
27
 
23
28
  == Download and Installation
24
29
 
@@ -27,7 +32,7 @@ You can download expectations from here[http://rubyforge.org/projects/expectatio
27
32
  $ gem install expectations
28
33
 
29
34
  == License
30
-
35
+
31
36
  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
37
 
33
38
  == TextMate
@@ -162,9 +167,22 @@ expectations can be used for state based and behavior based testing.
162
167
  process.finished = true
163
168
  end
164
169
 
170
+ expect Expectations::Results::Fulfilled do
171
+ suite = Expectations::Suite.new
172
+ suite.expect(NoMethodError) { Object.no_method }
173
+ suite.execute(Silent).expectations.first
174
+ end
175
+
165
176
  expect nil.to.be.nil?
166
177
  expect Object.not.to.be.nil?
167
178
 
179
+ # Shorthand style expectations
180
+ expect(1 + 1) == 2
181
+ expect(1 + 2) != 2
182
+ expect(1) < 2
183
+ expect(2) > 1
184
+ expect('foo bar') =~ /foo/
185
+
168
186
  end
169
187
 
170
188
  == Contributors
@@ -1,3 +1,5 @@
1
+ $stdout.sync = true
2
+
1
3
  module Expectations
2
4
  end
3
5
 
@@ -20,6 +22,7 @@ require File.expand_path(File.dirname(__FILE__) + '/expectations/recorder')
20
22
  require File.expand_path(File.dirname(__FILE__) + '/expectations/delegate_recorder')
21
23
  require File.expand_path(File.dirname(__FILE__) + '/expectations/recorded_expectation')
22
24
  require File.expand_path(File.dirname(__FILE__) + '/expectations/state_based_recorder')
25
+ require File.expand_path(File.dirname(__FILE__) + '/expectations/state_based_recorder_for_expectations_without_block')
23
26
  require File.expand_path(File.dirname(__FILE__) + '/expectations/reverse_result')
24
27
  require File.expand_path(File.dirname(__FILE__) + '/expectations/xml_string')
25
28
  require File.expand_path(File.dirname(__FILE__) + '/expectations/regexp')
@@ -20,10 +20,11 @@ class Expectations::BlankSlate
20
20
  # Hide the method named +name+ in the BlankSlate class. Don't
21
21
  # hide +instance_eval+ or any method beginning with "__".
22
22
  def hide(name)
23
- if instance_methods.include?(name.to_s) and
24
- name !~ /^(__|instance_eval|extend|is_a?)/
23
+ method_name = RUBY_VERSION < '1.9' ? name.to_s : name.to_sym
24
+ if instance_methods.include?(method_name) and
25
+ name !~ /^(__|instance_eval|extend|is_a?|object_id)/
25
26
  @hidden_methods ||= {}
26
- @hidden_methods[name.to_sym] = instance_method(name)
27
+ @hidden_methods[name.to_sym] = instance_method(method_name)
27
28
  undef_method name
28
29
  end
29
30
  end
@@ -1,39 +1,39 @@
1
1
  module Expectations::DelegateRecorder
2
2
  attr_accessor :delegation_result
3
-
3
+
4
4
  def delegate!(meth)
5
5
  @meth = meth
6
6
  recorder = self
7
7
  mod = Module.new do
8
8
  define_method meth do |*args|
9
- recorder.delegation_result = super
9
+ recorder.delegation_result = super(*args)
10
10
  end
11
11
  end
12
12
  subject.extend mod
13
13
  end
14
-
14
+
15
15
  def to(receiver)
16
16
  @receiver = receiver
17
17
  self
18
18
  end
19
-
19
+
20
20
  def subject!
21
21
  @subject_mock = Object.new
22
22
  @subject_mock.expects(@meth).returns(:a_delegated_return_value)
23
23
  subject.stubs(@receiver).returns(@subject_mock)
24
24
  subject
25
25
  end
26
-
26
+
27
27
  def verify
28
28
  :a_delegated_return_value == delegation_result
29
29
  end
30
-
30
+
31
31
  def failure_message
32
32
  "expected #{subject}.#{@meth} to return the value of #{subject}.#{@receiver}.#{@meth}; however, #{subject}.#{@meth} returned #{delegation_result.inspect}"
33
33
  end
34
-
34
+
35
35
  def mocha_error_message(ex)
36
36
  "expected #{subject} to delegate #{@meth} to #{@receiver}; however, #{subject}.#{@meth} was never called -- #{ex}"
37
37
  end
38
-
38
+
39
39
  end
@@ -1,21 +1,31 @@
1
1
  class Expectations::Expectation
2
- include Mocha::Standalone
2
+ include Mocha::API
3
3
  attr_accessor :expected, :block, :file, :line, :actual
4
-
4
+
5
5
  def initialize(expected, file, line, &block)
6
- self.expected, self.block = expected, block
6
+ self.expected = expected
7
+ self.block = block
7
8
  self.file, self.line = file, line.to_i
8
- case
9
- when expected.is_a?(Expectations::Recorder) then extend(Expectations::RecordedExpectation)
10
- else extend(Expectations::StateBasedExpectation)
9
+
10
+ if expected.is_a?(Expectations::Recorder)
11
+ extend(Expectations::RecordedExpectation)
12
+ elsif !block
13
+ extend(Expectations::RecordedExpectation)
14
+ self.expected = Expectations::Recorder.new(self.expected)
15
+ self.expected.extend(Expectations::StateBasedRecorder)
16
+ self.expected.extend(Expectations::StateBasedRecorderForExpectationsWithoutBlock)
17
+ self.expected.file = file
18
+ self.expected.line = line
19
+ else
20
+ extend(Expectations::StateBasedExpectation)
11
21
  end
12
22
  end
13
-
23
+
14
24
  def mock(*args)
15
25
  Expectations::StandardError.print "mock method called from #{caller.first.chomp(":in `__instance_exec0'")}\n"
16
26
  super
17
27
  end
18
-
28
+
19
29
  def warn_for_expects
20
30
  Object.__which_expects__ = ExpectationsExpectsMethod
21
31
  yield
@@ -1,34 +1,34 @@
1
1
  class Expectations::Recorder < Expectations::BlankSlate
2
-
2
+
3
3
  attr_reader :subject
4
4
  def initialize(subject)
5
5
  @subject = subject
6
6
  end
7
-
7
+
8
8
  def receive(meth)
9
9
  extend Expectations::MockRecorder
10
10
  receive!(meth)
11
11
  self
12
12
  end
13
-
13
+
14
14
  def have
15
15
  extend Expectations::StateBasedRecorder
16
16
  message_parts << "to have"
17
17
  self
18
18
  end
19
-
19
+
20
20
  def be
21
21
  extend Expectations::StateBasedRecorder
22
22
  message_parts << "to be"
23
23
  self
24
24
  end
25
-
25
+
26
26
  def delegate(method)
27
27
  extend Expectations::DelegateRecorder
28
28
  delegate!(method)
29
29
  self
30
30
  end
31
-
31
+
32
32
  def subject!
33
33
  subject
34
34
  end
@@ -36,9 +36,9 @@ class Expectations::Recorder < Expectations::BlankSlate
36
36
  def not!
37
37
  extend Expectations::ReverseResult
38
38
  end
39
-
39
+
40
40
  def verify!
41
41
  verify
42
42
  end
43
-
43
+
44
44
  end
@@ -3,7 +3,11 @@ module Expectations::StateBasedExpectation
3
3
  begin
4
4
  mocha_setup
5
5
  warn_for_expects do
6
- self.actual = instance_eval(&block)
6
+ unless block
7
+ self.actual = false
8
+ else
9
+ self.actual = instance_eval(&block)
10
+ end
7
11
  end
8
12
  mocha_verify
9
13
  if expected.expectations_equal_to(actual)
@@ -14,7 +18,7 @@ module Expectations::StateBasedExpectation
14
18
  rescue Exception => ex
15
19
  return self.extend(Expectations::Results::Fulfilled) if expected == ex.class
16
20
  self.extend(Expectations::Results::Error)
17
- self.exception = ex
21
+ self.exception = ex
18
22
  self.message = "expected: <#{expected.inspect}> got: <#{ex.class.inspect}>" if expected.is_a?(Class) && expected < StandardError
19
23
  return self
20
24
  ensure
@@ -3,7 +3,7 @@ module Expectations::StateBasedRecorder
3
3
  def verify
4
4
  method_stack.inject(subject) { |result, element| result.send element.first, *element.last }
5
5
  end
6
-
6
+
7
7
  def failure_message
8
8
  "expected #{subject} #{@message_parts.join(" ")}"
9
9
  end
@@ -11,12 +11,13 @@ module Expectations::StateBasedRecorder
11
11
  def method_stack
12
12
  @method_stack ||= []
13
13
  end
14
-
14
+
15
15
  def message_parts
16
16
  @message_parts ||= self.is_a?(Expectations::ReverseResult) ? [:not] : []
17
17
  end
18
-
18
+
19
19
  def method_missing(sym, *args)
20
+ @message_parts ||= []
20
21
  @message_parts << "#{sym}"
21
22
  args.each { |arg| @message_parts << arg.inspect }
22
23
  method_stack << [sym, args]
@@ -0,0 +1,11 @@
1
+ module Expectations::StateBasedRecorderForExpectationsWithoutBlock
2
+
3
+ attr_accessor :file, :line
4
+
5
+ def failure_message
6
+ "expected: <" +
7
+ File.read(file).split("\n")[line.to_i - 1].strip +
8
+ "> got: <#{subject} #{@message_parts.join(" ")}>"
9
+ end
10
+
11
+ end
@@ -1,18 +1,18 @@
1
1
  class Expectations::Suite
2
-
3
- include Mocha::Standalone
2
+
3
+ include Mocha::API
4
4
  class << self
5
5
  attr_accessor :silent
6
6
  end
7
-
7
+
8
8
  def initialize
9
9
  @do_not_run = false
10
10
  end
11
-
11
+
12
12
  def xml(string)
13
13
  Expectations::XmlString.new(string)
14
14
  end
15
-
15
+
16
16
  def execute(out=STDOUT, suite_result = Expectations::SuiteResults.new(out))
17
17
  return suite_result if @do_not_run
18
18
  benchmark = Benchmark.measure do
@@ -22,15 +22,17 @@ class Expectations::Suite
22
22
  suite_result.write_junit_xml(ENV["JUnitXmlPath"]) unless ENV["JUnitXmlPath"].nil?
23
23
  suite_result
24
24
  end
25
-
25
+
26
26
  def expect(expected, &block)
27
- expectations << Expectations::Expectation.new(expected, *caller.first.match(/\A(.+):(\d+)\Z/)[1..2], &block)
27
+ file, line = *caller.first.match(/\A(.+):(\d+)/)[1..2]
28
+ expectations << Expectations::Expectation.new(expected, file, line, &block)
29
+ expectations.last.expected
28
30
  end
29
-
31
+
30
32
  def do_not_run
31
33
  @do_not_run = true
32
34
  end
33
-
35
+
34
36
  def expectations_for(line)
35
37
  return expectations if line.nil?
36
38
  [expectations.inject { |result, expectation| expectation.line > line.to_i ? result : expectation }]
@@ -39,5 +41,5 @@ class Expectations::Suite
39
41
  def expectations
40
42
  @expectations ||= []
41
43
  end
42
-
44
+
43
45
  end
@@ -27,18 +27,18 @@ class Expectations::SuiteResults
27
27
  def failures
28
28
  expectations.select { |expectation| expectation.failure? }
29
29
  end
30
-
30
+
31
31
  def print_results(benchmark)
32
32
  run_time = benchmark.real
33
33
  run_time = 0.001 if run_time < 0.001
34
34
  out.puts "\nFinished in #{run_time.to_s.gsub(/(\d*)\.(\d{0,5}).*/,'\1.\2')} seconds"
35
35
  if succeeded?
36
- print_success
36
+ print_success
37
37
  else
38
38
  print_fail
39
39
  end
40
40
  end
41
-
41
+
42
42
  def print_success
43
43
  out.puts "\nSuccess: #{fulfilled.size} fulfilled"
44
44
  end
@@ -47,17 +47,17 @@ class Expectations::SuiteResults
47
47
  out.puts "\nFailure: #{failures.size} failed, #{errors.size} errors, #{fulfilled.size} fulfilled"
48
48
  out.puts "\n--Errors--" if errors.any?
49
49
  errors.each do |error|
50
- out.puts " #{error.file}:#{error.line}:in `expect'" if ENV["TM_MODE"]
50
+ out.puts "#{error.file}:#{error.line}:in `expect'" if ENV["TM_MODE"]
51
51
  out.puts "file <#{error.file}>"
52
52
  out.puts "line <#{error.line}>"
53
53
  out.puts "error <#{error.exception.message}>"
54
- out.puts "trace #{filter_backtrace(error.exception.backtrace)}"
54
+ out.puts "trace #{filter_backtrace(error.exception.backtrace).join('')}"
55
55
  out.puts "#{error.message}" if error.message && error.message.any?
56
56
  out.puts "\n"
57
57
  end
58
58
  out.puts "\n--Failures--" if failures.any?
59
59
  failures.each do |failure|
60
- out.puts " #{failure.file}:#{failure.line}:in `expect'" if ENV["TM_MODE"]
60
+ out.puts "#{failure.file}:#{failure.line}:in `expect'" if ENV["TM_MODE"]
61
61
  out.puts "file <#{failure.file}>"
62
62
  out.puts "line <#{failure.line}>"
63
63
  out.puts "#{failure.message}\n\n"
@@ -67,7 +67,7 @@ class Expectations::SuiteResults
67
67
  def write_junit_xml(path)
68
68
  FileUtils.rm_rf path if File.exist?(path)
69
69
  FileUtils.mkdir_p path
70
- grouped_expectations = expectations.inject({}) do |result, expectation|
70
+ grouped_expectations = expectations.inject({}) do |result, expectation|
71
71
  result[expectation.file] = [] if result[expectation.file].nil?
72
72
  result[expectation.file] << expectation
73
73
  result
@@ -91,12 +91,12 @@ class Expectations::SuiteResults
91
91
  end
92
92
 
93
93
  def filter_backtrace(trace)
94
- patterns_to_strip = [/\/expectations\/lib\/expectations\//, /\/lib\/ruby\/1\.8\//]
94
+ patterns_to_strip = [/\/expectations\/lib\/expectations\//, /\/lib\/ruby\/1\.[89]/]
95
95
  result = patterns_to_strip.inject(trace) do |result, element|
96
96
  result = result.select { |line| line !~ element}
97
97
  end
98
98
  result.collect do |line|
99
- "\n #{line}"
99
+ "\n#{line}"
100
100
  end
101
101
  end
102
102
  end
@@ -9,7 +9,7 @@ task :default => [:test]
9
9
  Rake::TestTask.new do |t|
10
10
  t.libs << "test"
11
11
  t.pattern = 'test/**/*_test.rb'
12
- t.verbose = true
12
+ t.verbose = false
13
13
  end
14
14
 
15
15
  desc 'Generate RDoc'
@@ -30,28 +30,30 @@ desc "Upload RDoc to RubyForge"
30
30
  task :publish_rdoc do
31
31
  Rake::Task[:readme].invoke
32
32
  Rake::Task[:rdoc].invoke
33
- Rake::SshDirPublisher.new("jaycfields@rubyforge.org", "/var/www/gforge-projects/expectations", "doc").upload
33
+ Rake::SshDirPublisher.new("holgerkohnen@rubyforge.org", "/var/www/gforge-projects/expectations", "doc").upload
34
34
  end
35
35
 
36
36
  specification = Gem::Specification.new do |s|
37
37
  s.name = "expectations"
38
- s.summary = "A lightweight unit testing framework. Tests (expectations) will be written as follows
39
- expect 2 do
40
- 1 + 1
41
- end
38
+ s.summary = "A lightweight unit testing framework. Tests (expectations) will be written as follows
39
+ expect 2 do
40
+ 1 + 1
41
+ end
42
42
 
43
- expect NoMethodError do
44
- Object.invalid_method_call
43
+ expect NoMethodError do
44
+ Object.invalid_method_call
45
45
  end."
46
- s.version = "1.2.1"
46
+ s.version = "2.0.0"
47
47
  s.author = 'Jay Fields'
48
- s.description = "A lightweight unit testing framework. Tests (expectations) will be written as follows
49
- expect 2 do
50
- 1 + 1
51
- end
48
+ s.description = "A lightweight unit testing framework. Tests (expectations) will be written as follows
49
+ expect 2 do
50
+ 1 + 1
51
+ end
52
52
 
53
- expect NoMethodError do
54
- Object.invalid_method_call
53
+ expect(1 + 1) == 2
54
+
55
+ expect NoMethodError do
56
+ Object.invalid_method_call
55
57
  end."
56
58
  s.homepage = 'http://expectations.rubyforge.org'
57
59
  s.rubyforge_project = 'expectations'
@@ -4,25 +4,37 @@ Expectations do
4
4
  expect Expectations::Results::StateBasedFailure do
5
5
  Expectations::Expectation.new(1, nil, nil) { 2 }.execute
6
6
  end
7
-
7
+
8
8
  expect Expectations::Results::Fulfilled do
9
9
  Expectations::Expectation.new(1, nil, nil) { 1 }.execute
10
10
  end
11
-
11
+
12
12
  expect Expectations::Results::Error do
13
13
  Expectations::Expectation.new(1, nil, nil) { raise }.execute
14
14
  end
15
-
15
+
16
16
  expect "undefined method `no_method' for Object:Class" do
17
17
  Expectations::Expectation.new(ArgumentError, nil, nil) { Object.no_method }.execute.exception.to_s
18
18
  end
19
-
19
+
20
20
  expect Expectations::Results::Fulfilled do
21
21
  Expectations::Expectation.new(NoMethodError, nil, nil) { Object.no_method }.execute
22
22
  end
23
-
23
+
24
24
  expect nil do
25
25
  Expectations::Expectation.new(String, nil, nil) { Object.no_method }.execute.actual
26
26
  end
27
-
27
+
28
+ expect Expectations::StateBasedRecorder do
29
+ ''.to.have.to_s == ''
30
+ end
31
+
32
+ expect Expectations::Results::StateBasedFailure do
33
+ Expectations::Expectation.new('foo'.to.have.to_s == 'bar', nil, nil).execute
34
+ end
35
+
36
+ expect Expectations::Results::Fulfilled do
37
+ Expectations::Expectation.new('foo'.to.have.to_s == 'foo', nil, nil).execute
38
+ end
39
+
28
40
  end
@@ -0,0 +1,40 @@
1
+ require File.dirname(__FILE__) + "/../test_helper"
2
+
3
+ Expectations do
4
+ expect Expectations::Results::StateBasedFailure do
5
+ suite = Expectations::Suite.new
6
+ suite.expect(3) == 4
7
+ suite.execute(Silent)
8
+ suite.expectations.first
9
+ end
10
+
11
+ expect 'expected: <suite.expect(value) == 4> got: <3 == 4>' do
12
+ suite = Expectations::Suite.new
13
+ value = 3
14
+ suite.expect(value) == 4
15
+ suite.execute(Silent)
16
+ suite.expectations.first.message
17
+ end
18
+
19
+ expect Expectations::Results::Fulfilled do
20
+ suite = Expectations::Suite.new
21
+ suite.expect(3) == 3
22
+ suite.execute(Silent)
23
+ suite.expectations.first
24
+ end
25
+
26
+ expect Expectations::Results::Fulfilled do
27
+ suite = Expectations::Suite.new
28
+ suite.expect('foo bar') =~ /foo/
29
+ suite.execute(Silent)
30
+ suite.expectations.first
31
+ end
32
+
33
+ expect Expectations::Results::StateBasedFailure do
34
+ suite = Expectations::Suite.new
35
+ suite.expect('bar') =~ /foo/
36
+ suite.execute(Silent)
37
+ suite.expectations.first
38
+ end
39
+
40
+ end
@@ -5,6 +5,10 @@ Expectations do
5
5
  String.expectations_equal_to "foo"
6
6
  end
7
7
 
8
+ expect false do
9
+ String.expectations_equal_to 0
10
+ end
11
+
8
12
  expect true do
9
13
  String.expectations_equal_to String
10
14
  end
@@ -8,4 +8,8 @@ Expectations do
8
8
  expect true do
9
9
  (1..5).expectations_equal_to 1..5
10
10
  end
11
+
12
+ expect false do
13
+ (1..5).expectations_equal_to 6
14
+ end
11
15
  end
@@ -8,4 +8,8 @@ Expectations do
8
8
  expect true do
9
9
  /foo/.expectations_equal_to /foo/
10
10
  end
11
+
12
+ expect false do
13
+ /foo/.expectations_equal_to /bar/
14
+ end
11
15
  end
@@ -5,6 +5,7 @@ Expectations do
5
5
  expect Object.new.extend(Expectations::Results::StateBasedFailure).to.have.char == "F"
6
6
  expect Object.new.extend(Expectations::Results::BehaviorBasedFailure).to.have.char == "F"
7
7
  expect Object.new.extend(Expectations::Results::Error).to.have.char == "E"
8
+
8
9
  expect Object.new.extend(Expectations::Results::Fulfilled).to.be.fulfilled?
9
10
  expect Object.new.extend(Expectations::Results::StateBasedFailure).not.to.be.fulfilled?
10
11
  expect Object.new.extend(Expectations::Results::BehaviorBasedFailure).not.to.be.fulfilled?
@@ -6,13 +6,7 @@ Expectations do
6
6
  suite.expect(2) { 3 }
7
7
  suite.execute(Silent).expectations.first
8
8
  end
9
-
10
- expect Expectations::Results::Error do
11
- suite = Expectations::Suite.new
12
- suite.expect(ArgumentError) { Object.no_method }
13
- suite.execute(Silent).expectations.first
14
- end
15
-
9
+
16
10
  expect Expectations::Results::BehaviorBasedFailure do
17
11
  Expectations::StandardError.silence
18
12
  suite = Expectations::Suite.new
@@ -27,25 +21,25 @@ Expectations do
27
21
  expect Expectations::Results::BehaviorBasedFailure do
28
22
  Expectations::StandardError.stubs(:print)
29
23
  suite = Expectations::Suite.new
30
- suite.expect mock.to.receive(:dial).with("2125551212").times(2) do |phone|
24
+ suite.expect mock.to.receive(:dial).with("2125551212").times(2) do |phone|
31
25
  phone.dial("2125551212")
32
26
  end
33
27
  suite.execute(Silent).expectations.first
34
28
  end
35
-
29
+
36
30
  expect Expectations::Results::BehaviorBasedFailure do
37
31
  Expectations::StandardError.stubs(:print)
38
32
  suite = Expectations::Suite.new
39
33
  suite.expect(Object.to.receive(:deal)) { }
40
34
  suite.execute(Silent).expectations.first
41
35
  end
42
-
36
+
43
37
  expect Expectations::Results::Error do
44
38
  suite = Expectations::Suite.new
45
39
  suite.expect(2) { stub(:two => 2).twos }
46
40
  suite.execute(Silent).expectations.first
47
41
  end
48
-
42
+
49
43
  expect Expectations::Results::Error do
50
44
  Expectations::StandardError.stubs(:print)
51
45
  suite = Expectations::Suite.new
@@ -55,7 +49,7 @@ Expectations do
55
49
  end
56
50
  suite.execute(Silent).expectations.first
57
51
  end
58
-
52
+
59
53
  expect Expectations::Results::Error do
60
54
  Expectations::StandardError.stubs(:print)
61
55
  suite = Expectations::Suite.new
@@ -65,7 +59,7 @@ Expectations do
65
59
  end
66
60
  suite.execute(Silent).expectations.first
67
61
  end
68
-
62
+
69
63
  expect Expectations::Results::Error do
70
64
  Expectations::StandardError.stubs(:print)
71
65
  suite = Expectations::Suite.new
@@ -74,7 +68,7 @@ Expectations do
74
68
  end
75
69
  suite.execute(Silent).expectations.first
76
70
  end
77
-
71
+
78
72
  expect Expectations::Results::Error do
79
73
  Expectations::StandardError.stubs(:print)
80
74
  suite = Expectations::Suite.new
@@ -83,7 +77,7 @@ Expectations do
83
77
  end
84
78
  suite.execute(Silent).expectations.first
85
79
  end
86
-
80
+
87
81
  expect Expectations::Results::BehaviorBasedFailure do
88
82
  Expectations::StandardError.stubs(:print)
89
83
  suite = Expectations::Suite.new
@@ -93,7 +87,7 @@ Expectations do
93
87
  end
94
88
  suite.execute(Silent).expectations.first
95
89
  end
96
-
90
+
97
91
  expect Expectations::Results::BehaviorBasedFailure do
98
92
  Expectations::StandardError.stubs(:print)
99
93
  suite = Expectations::Suite.new
@@ -103,5 +97,5 @@ Expectations do
103
97
  end
104
98
  suite.execute(Silent).expectations.first
105
99
  end
106
-
100
+
107
101
  end
@@ -118,7 +118,20 @@ Expectations do
118
118
  process.finished = true
119
119
  end
120
120
 
121
+ expect Expectations::Results::Fulfilled do
122
+ suite = Expectations::Suite.new
123
+ suite.expect(NoMethodError) { Object.no_method }
124
+ suite.execute(Silent).expectations.first
125
+ end
126
+
121
127
  expect nil.to.be.nil?
122
128
  expect Object.not.to.be.nil?
123
129
 
130
+ # Shorthand style expectations
131
+ expect(1 + 1) == 2
132
+ expect(1 + 2) != 2
133
+ expect(1) < 2
134
+ expect(2) > 1
135
+ expect('foo bar') =~ /foo/
136
+
124
137
  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: 1.2.1
4
+ version: 2.0.0
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: 2009-04-22 00:00:00 +02:00
12
+ date: 2010-02-13 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -22,7 +22,17 @@ dependencies:
22
22
  - !ruby/object:Gem::Version
23
23
  version: 0.5.5
24
24
  version:
25
- description: A lightweight unit testing framework. Tests (expectations) will be written as follows expect 2 do 1 + 1 end expect NoMethodError do Object.invalid_method_call end.
25
+ description: |-
26
+ A lightweight unit testing framework. Tests (expectations) will be written as follows
27
+ expect 2 do
28
+ 1 + 1
29
+ end
30
+
31
+ expect(1 + 1) == 2
32
+
33
+ expect NoMethodError do
34
+ Object.invalid_method_call
35
+ end.
26
36
  email: ruby@jayfields.com
27
37
  executables: []
28
38
 
@@ -32,6 +42,7 @@ extra_rdoc_files:
32
42
  - README
33
43
  files:
34
44
  - lib/expectations.rb
45
+ - lib/expectations/state_based_recorder_for_expectations_without_block.rb
35
46
  - lib/expectations/range.rb
36
47
  - lib/expectations/reverse_result.rb
37
48
  - lib/expectations/blank_slate.rb
@@ -57,6 +68,7 @@ files:
57
68
  - test/test_helper.rb
58
69
  - test/successes_test.rb
59
70
  - test/expectations/regexp_test.rb
71
+ - test/expectations/expectation_without_block_test.rb
60
72
  - test/expectations/suite_runner_test.rb
61
73
  - test/expectations/expectation_test.rb
62
74
  - test/expectations/string_test.rb
@@ -72,6 +84,8 @@ files:
72
84
  - README
73
85
  has_rdoc: true
74
86
  homepage: http://expectations.rubyforge.org
87
+ licenses: []
88
+
75
89
  post_install_message:
76
90
  rdoc_options:
77
91
  - --title
@@ -96,9 +110,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
110
  requirements: []
97
111
 
98
112
  rubyforge_project: expectations
99
- rubygems_version: 1.3.1
113
+ rubygems_version: 1.3.5
100
114
  signing_key:
101
- specification_version: 2
102
- summary: A lightweight unit testing framework. Tests (expectations) will be written as follows expect 2 do 1 + 1 end expect NoMethodError do Object.invalid_method_call end.
115
+ specification_version: 3
116
+ summary: A lightweight unit testing framework. Tests (expectations) will be written as follows expect 2 do 1 + 1 end expect NoMethodError do Object.invalid_method_call end.
103
117
  test_files: []
104
118