peck 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -100,6 +100,33 @@ created.
100
100
  emd
101
101
  end
102
102
 
103
+ Except extension you can also add should macros which defined one or more
104
+ specifications:
105
+
106
+ class Peck::Should::Specification
107
+ class Disallow < Peck::Should::Proxy
108
+ def get(action)
109
+ context.it("disallows GET on `#{action}'") do
110
+ get action
111
+ response.should == :unauthorized
112
+ end
113
+ end
114
+ end
115
+
116
+ def disallow
117
+ Peck::Should::Specification::Disallow.new(context)
118
+ end
119
+ end
120
+
121
+ describe CertificatesController, "when accessed by a regular user" do
122
+ before do
123
+ login :regular_user
124
+ end
125
+
126
+ should.disallow.get :index
127
+ should.disallow.get :show
128
+ end
129
+
103
130
  ## Documentation
104
131
 
105
132
  Peck is still very much in flux and will probably change a lot in the coming
data/lib/peck/context.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  class Peck
2
4
  class Context
3
5
  attr_reader :specification
@@ -10,6 +12,10 @@ class Peck
10
12
  self.class.describe(*args, &block)
11
13
  end
12
14
 
15
+ def inspect
16
+ "#<Peck::Context:0x#{object_id.to_s(16)} @description=\"#{self.class.label}\">"
17
+ end
18
+
13
19
  class << self
14
20
  FILENAME_WITHOUT_LINE_RE = /^(.+?):\d+/
15
21
 
@@ -53,7 +59,11 @@ class Peck
53
59
  init(@before, @after, *description, &block)
54
60
  end
55
61
  end
56
-
62
+
63
+ def inspect
64
+ "#<Peck::Context description=\"#{@description[0]}…\">"
65
+ end
66
+
57
67
  # Is only ran once for every context when it's initialized. Great place
58
68
  # to hook in test suite specific functionality.
59
69
  #
@@ -62,7 +72,7 @@ class Peck
62
72
  @setup ||= []
63
73
  @setup << block
64
74
  end
65
-
75
+
66
76
  def before(*args, &block)
67
77
  add_callback(@before, *args, &block)
68
78
  end
data/lib/peck/counter.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  class Peck
2
4
  class << self
3
5
  attr_accessor :counter
data/lib/peck/debug.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  class Peck
2
4
  def self.logger
3
5
  @logger ||= begin
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'set'
2
4
 
3
5
  class Peck
data/lib/peck/error.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  class Peck
2
4
  class Error < RuntimeError
3
5
  attr_accessor :type
@@ -1,7 +1,27 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'peck/error'
2
4
 
3
5
  class Peck
4
6
  class Should
7
+ class Proxy
8
+ attr_accessor :negated
9
+ attr_reader :context, :block
10
+
11
+ def initialize(context, &block)
12
+ @context = context
13
+ @block = block
14
+ @negated = false
15
+ end
16
+ end
17
+
18
+ class Specification < Proxy
19
+ def not
20
+ @negated = !@negated
21
+ self
22
+ end
23
+ end
24
+
5
25
  # Kills ==, ===, =~, eql?, equal?, frozen?, instance_of?, is_a?,
6
26
  # kind_of?, nil?, respond_to?, tainted?
7
27
  KILL_METHODS_RE = /\?|^\W+$/
@@ -110,6 +130,11 @@ end
110
130
 
111
131
  class Object
112
132
  def should(*args, &block)
113
- Peck::Should.new(self).be(*args, &block)
133
+ # TODO: raise argument error when .should.should
134
+ if self.kind_of?(Class) && (self < Peck::Context)
135
+ Peck::Should::Specification.new(self)
136
+ else
137
+ Peck::Should.new(self).be(*args, &block)
138
+ end
114
139
  end
115
140
  end
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'peck'
2
4
  require 'peck/delegates'
3
5
  require 'peck/counter'
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'peck'
2
4
  require 'peck/delegates'
3
5
  require 'peck/counter'
@@ -1,11 +1,28 @@
1
+ # encoding: utf-8
2
+
1
3
  class Peck
2
4
  class Notifiers
3
5
  class Base
4
- # When a file starts with this path, it's in the Peck library
5
- PECK_PATH = File.expand_path('../../../../', __FILE__)
6
+ module BacktraceCleaning
7
+ # When a file starts with this path, it's in the Peck library
8
+ PECK_PATH = File.expand_path('../../../../', __FILE__)
9
+
10
+ # Matches: `block (2 levels) in <top (required)>'
11
+ ANONYMOUS_BLOCK_RE = /`block/
6
12
 
7
- # Matches: `block (2 levels) in <top (required)>'
8
- ANONYMOUS_BLOCK_RE = /`block/
13
+ def clean_backtrace(backtrace)
14
+ stripped = []
15
+ backtrace.each do |line|
16
+ if line.start_with?(PECK_PATH) || line.start_with?("<")
17
+ elsif line =~ ANONYMOUS_BLOCK_RE
18
+ stripped << line.split(':')[0,2].join(':')
19
+ else
20
+ stripped << line
21
+ end
22
+ end
23
+ stripped.empty? ? backtrace : stripped
24
+ end
25
+ end
9
26
 
10
27
  def self.use
11
28
  @instance ||= begin
@@ -22,18 +39,7 @@ class Peck
22
39
  count == 1 ? stem : "#{stem}s"
23
40
  end
24
41
 
25
- def clean_backtrace(backtrace)
26
- stripped = []
27
- backtrace.each do |line|
28
- if line.start_with?(PECK_PATH) || line.start_with?("<")
29
- elsif line =~ ANONYMOUS_BLOCK_RE
30
- stripped << line.split(':')[0,2].join(':')
31
- else
32
- stripped << line
33
- end
34
- end
35
- stripped.empty? ? backtrace : stripped
36
- end
42
+ include BacktraceCleaning
37
43
  end
38
44
  end
39
45
  end
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'peck/notifiers/base'
2
4
 
3
5
  class Peck
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  class Peck
2
4
  class Context
3
5
  def self.it(description, &block)
@@ -49,7 +51,8 @@ class Peck
49
51
  end
50
52
  end
51
53
 
52
- def run
54
+ def run delegates
55
+ delegates.started_specification(self)
53
56
  if @block
54
57
  @before.each { |cb| @context.instance_eval(&cb) }
55
58
  begin
@@ -63,11 +66,13 @@ class Peck
63
66
  @after.each { |cb| @context.instance_eval(&cb) }
64
67
  end
65
68
  else
66
- Peck.delegates.received_missing(self)
69
+ delegates.received_missing(self)
67
70
  end
68
71
  rescue Object => e
69
72
  Peck.delegates.received_exception(self, e)
70
73
  @events << Event.new(e, self)
74
+ ensure
75
+ delegates.finished_specification(self)
71
76
  end
72
77
 
73
78
  def empty?
data/lib/peck.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  class Peck
2
4
  VERSION = "0.1.0"
3
5
 
@@ -75,9 +77,7 @@ class Peck
75
77
  Thread.current['peck-semaphore'] = Mutex.new
76
78
  contexts.each do |context|
77
79
  context.specs.each do |specification|
78
- delegates.started_specification(specification)
79
- specification.run
80
- delegates.finished_specification(specification)
80
+ specification.run(delegates)
81
81
  end
82
82
  end
83
83
  rescue Exception => e
@@ -94,9 +94,7 @@ class Peck
94
94
  loop do
95
95
  spec_index = Thread.exclusive { current_spec += 1 }
96
96
  if specification = specs[spec_index]
97
- delegates.started_specification(specification)
98
- specification.run
99
- delegates.finished_specification(specification)
97
+ specification.run(delegates)
100
98
  else
101
99
  break
102
100
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: peck
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-26 00:00:00.000000000 Z
12
+ date: 2012-09-28 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ! ' Concurrent spec framework.
15
15
 
@@ -55,7 +55,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
55
55
  version: '0'
56
56
  requirements: []
57
57
  rubyforge_project:
58
- rubygems_version: 1.8.11
58
+ rubygems_version: 1.8.23
59
59
  signing_key:
60
60
  specification_version: 3
61
61
  summary: Peck is a concurrent spec framework which inherits a lot from the fabulous