Permalink
Browse files

initial

  • Loading branch information...
0 parents commit 145e772d6c54dff87a4a14aa02fd0a410a67b9e4 @grosser committed Aug 23, 2012
Showing with 135 additions and 0 deletions.
  1. +4 −0 .travis.yml
  2. +6 −0 Gemfile
  3. +21 −0 Gemfile.lock
  4. +6 −0 Rakefile
  5. +56 −0 Readme.md
  6. +21 −0 lib/shoulda/let.rb
  7. +11 −0 shoulda-let.gemspec
  8. +10 −0 test/shoulda_let_test.rb
@@ -0,0 +1,4 @@
+rvm:
+ - ree
+ - 1.9.2
+ - 1.9.3
@@ -0,0 +1,6 @@
+source :rubygems
+gemspec
+
+gem "rake"
+gem "test-unit", ">=2.5.1"
+gem "shoulda", "~>2.11"
@@ -0,0 +1,21 @@
+PATH
+ remote: .
+ specs:
+ shoulda-let (0.0.1)
+ shoulda
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ rake (0.9.2)
+ shoulda (2.11.3)
+ test-unit (2.5.1)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ rake
+ shoulda (~> 2.11)
+ shoulda-let!
+ test-unit (>= 2.5.1)
@@ -0,0 +1,6 @@
+require "bundler/gem_tasks"
+
+task :default do
+ sh "ruby test/shoulda_let_test.rb"
+end
+
@@ -0,0 +1,56 @@
+A simple let for shoulda
+
+Install
+=======
+
+ gem install shoulda-let
+
+ # Gemfile
+ gem "shoulda-let", :require => "shoulda/let"
+
+Usage
+=====
+<!-- example -->
+ context "foo" do
+ setup do
+ @result = let(:thing)
+ end
+
+ let(:thing){ "parent" }
+
+ context "with something" do
+ let(:thing){ "something" }
+ should "be something" do
+ assert_equal "something", @result
+ end
+ end
+
+ context "with cache" do
+ let(:thing){ rand }
+
+ should "be stable" do
+ assert_equal @result, let(:thing)
+ end
+
+ should "be different" do
+ assert_not_equal $last_thing, let(:thing)
+ end
+
+ should "prepare for be different" do
+ $last_thing = let(:thing)
+ end
+ end
+
+ context "with parent" do
+ should "be parent" do
+ assert_equal "parent", @result
+ end
+ end
+ end
+<!-- example -->
+Author
+======
+[Michael Grosser](http://grosser.it)<br/>
+michael@grosser.it<br/>
+License: MIT<br/>
+[![Build Status](https://secure.travis-ci.org/grosser/shoulda_let.png)](http://travis-ci.org/grosser/shoulda_let)
@@ -0,0 +1,21 @@
+require "shoulda"
+
+Shoulda::Context.class_eval do
+ def let(name, &block)
+ @let ||= {}
+ if block
+ @let[name] = block
+ else
+ @let.fetch(name){ parent.let(name) }
+ end
+ end
+end
+
+Shoulda::InstanceMethods.class_eval do
+ def let(name)
+ @let ||= {}
+ @let.fetch(name) do
+ @let[name] = instance_exec(&@shoulda_context.let(name))
+ end
+ end
+end
@@ -0,0 +1,11 @@
+name = "shoulda-let"
+
+Gem::Specification.new name, "0.0.1" do |s|
+ s.summary = "A simple let for shoulda"
+ s.authors = ["Michael Grosser"]
+ s.email = "michael@grosser.it"
+ s.homepage = "http://github.com/grosser/#{name}"
+ s.files = `git ls-files`.split("\n")
+ s.license = "MIT"
+ s.add_runtime_dependency "shoulda"
+end
@@ -0,0 +1,10 @@
+require "test/unit"
+$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
+require "shoulda/let"
+
+class ShouldaLetTest < Test::Unit::TestCase
+ context "Readme" do
+ example = File.read(File.expand_path("../../Readme.md", __FILE__)).match(/<!-- example -->(.*)<!-- example -->/m)[1]
+ eval example
+ end
+end

0 comments on commit 145e772

Please sign in to comment.