diff --git a/README.md b/README.md index 2803b49..fa54408 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/examples/006_should_in_context_spec.rb b/examples/006_should_in_context_spec.rb new file mode 100644 index 0000000..a806011 --- /dev/null +++ b/examples/006_should_in_context_spec.rb @@ -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") diff --git a/lib/peck/expectations.rb b/lib/peck/expectations.rb index 151cbb4..def856f 100644 --- a/lib/peck/expectations.rb +++ b/lib/peck/expectations.rb @@ -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 \ No newline at end of file