Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

initial

  • Loading branch information...
commit 145e772d6c54dff87a4a14aa02fd0a410a67b9e4 0 parents
@grosser authored
4 .travis.yml
@@ -0,0 +1,4 @@
+rvm:
+ - ree
+ - 1.9.2
+ - 1.9.3
6 Gemfile
@@ -0,0 +1,6 @@
+source :rubygems
+gemspec
+
+gem "rake"
+gem "test-unit", ">=2.5.1"
+gem "shoulda", "~>2.11"
21 Gemfile.lock
@@ -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)
6 Rakefile
@@ -0,0 +1,6 @@
+require "bundler/gem_tasks"
+
+task :default do
+ sh "ruby test/shoulda_let_test.rb"
+end
+
56 Readme.md
@@ -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)
21 lib/shoulda/let.rb
@@ -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
11 shoulda-let.gemspec
@@ -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
10 test/shoulda_let_test.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.