Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Allow should to be called from the context.

This returns an instance of Peck::Should::Specification. In itself this
doesn't do anything, but it allows you to add methods to
Peck::Should::Specification so you can make stuff happen.

The most obvious thing is to create a specification like displayed in the
example (006).
  • Loading branch information...
commit b5078c4bbfab05ca9f088d2bf5d71a22e2c22df7 1 parent 2f3d65e
Manfred Stienstra Manfred authored
27 README.md
View
@@ -100,6 +100,33 @@ created.
emd
end
+Except extension you can also add should macros which defined one or more
+specifications:
+
+ class Peck::Should::Specification
+ class Disallow < Peck::Should::Proxy
+ def get(action)
+ context.it("disallows GET on `#{action}'") do
+ get action
+ response.should == :unauthorized
+ end
+ end
+ end
+
+ def disallow
+ Peck::Should::Specification::Disallow.new(context)
+ end
+ end
+
+ describe CertificatesController, "when accessed by a regular user" do
+ before do
+ login :regular_user
+ end
+
+ should.disallow.get :index
+ should.disallow.get :show
+ end
+
## Documentation
Peck is still very much in flux and will probably change a lot in the coming
24 examples/006_should_in_context_spec.rb
View
@@ -0,0 +1,24 @@
+require 'preamble'
+
+class Peck
+ class Should
+ class Specification
+ def handle_the_truth
+ context.it('handles the truth') do
+ true.should == true
+ end
+ end
+ end
+ end
+end
+
+describe "The test framework" do
+ should.handle_the_truth
+end
+
+Peck.run
+
+require 'assert'
+
+assert(Peck.counter.ran == 1,
+ "Expected 1 specification to have been run")
24 lib/peck/expectations.rb
View
@@ -2,6 +2,24 @@
class Peck
class Should
+ class Proxy
+ attr_accessor :negated
+ attr_reader :context, :block
+
+ def initialize(context, &block)
+ @context = context
+ @block = block
+ @negated = false
+ end
+ end
+
+ class Specification < Proxy
+ def not
+ @negated = !@negated
+ self
+ end
+ end
+
# Kills ==, ===, =~, eql?, equal?, frozen?, instance_of?, is_a?,
# kind_of?, nil?, respond_to?, tainted?
KILL_METHODS_RE = /\?|^\W+$/
@@ -110,6 +128,10 @@ def method_missing(name, *args, &block)
class Object
def should(*args, &block)
- Peck::Should.new(self).be(*args, &block)
+ if self.kind_of?(Class) && (self < Peck::Context)
+ Peck::Should::Specification.new(self)
+ else
+ Peck::Should.new(self).be(*args, &block)
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.