shoulda-context-1.1.2/0000755000004100000410000000000012147161361014666 5ustar www-datawww-datashoulda-context-1.1.2/MIT-LICENSE0000644000004100000410000000211612147161361016322 0ustar www-datawww-dataCopyright (c) 2006-2013, Tammer Saleh, thoughtbot, inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. shoulda-context-1.1.2/.travis.yml0000644000004100000410000000003112147161361016771 0ustar www-datawww-datarvm: - 1.9.3 - 2.0.0 shoulda-context-1.1.2/CONTRIBUTING.md0000644000004100000410000000247012147161361017122 0ustar www-datawww-dataWe love pull requests. Here's a quick guide: 1. Fork the repo. 2. Run the tests. We only take pull requests with passing tests, and it's great to know that you have a clean slate: `bundle && rake` 3. Add a test for your change. Only refactoring and documentation changes require no new tests. If you are adding functionality or fixing a bug, we need a test! 4. Make the test pass. 5. Push to your fork and submit a pull request. At this point you're waiting on us. We like to at least comment on, if not accept, pull requests within three business days (and, typically, one business day). We may suggest some changes or improvements or alternatives. Some things that will increase the chance that your pull request is accepted, taken straight from the Ruby on Rails guide: * Use Rails idioms and helpers * Include tests that fail without your code, and pass with it * Update the documentation, the surrounding one, examples elsewhere, guides, whatever is affected by your contribution Syntax: * Two spaces, no tabs. * No trailing whitespace. Blank lines should not have any space. * Prefer &&/|| over and/or. * MyClass.my_method(my_arg) not my_method( my_arg ) or my_method my_arg. * a = b and not a=b. * Follow the conventions you see used in the source already. And in case we didn't emphasize it enough: we love tests! shoulda-context-1.1.2/test/0000755000004100000410000000000012147161361015645 5ustar www-datawww-datashoulda-context-1.1.2/test/fake_rails_root/0000755000004100000410000000000012147161361021010 5ustar www-datawww-datashoulda-context-1.1.2/test/fake_rails_root/test/0000755000004100000410000000000012147161361021767 5ustar www-datawww-datashoulda-context-1.1.2/test/fake_rails_root/test/shoulda_macros/0000755000004100000410000000000012147161361024772 5ustar www-datawww-datashoulda-context-1.1.2/test/fake_rails_root/test/shoulda_macros/custom_macro.rb0000644000004100000410000000013212147161361030006 0ustar www-datawww-datamodule CustomMacro def custom_macro end end Test::Unit::TestCase.extend(CustomMacro) shoulda-context-1.1.2/test/fake_rails_root/vendor/0000755000004100000410000000000012147161361022305 5ustar www-datawww-datashoulda-context-1.1.2/test/fake_rails_root/vendor/gems/0000755000004100000410000000000012147161361023240 5ustar www-datawww-datashoulda-context-1.1.2/test/fake_rails_root/vendor/gems/gem_with_macro-0.0.1/0000755000004100000410000000000012147161361026656 5ustar www-datawww-datashoulda-context-1.1.2/test/fake_rails_root/vendor/gems/gem_with_macro-0.0.1/shoulda_macros/0000755000004100000410000000000012147161361031661 5ustar www-datawww-data././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootshoulda-context-1.1.2/test/fake_rails_root/vendor/gems/gem_with_macro-0.0.1/shoulda_macros/gem_macro.rbshoulda-context-1.1.2/test/fake_rails_root/vendor/gems/gem_with_macro-0.0.1/shoulda_macros/gem_macro0000644000004100000410000000012112147161361033527 0ustar www-datawww-datamodule GemMacro def gem_macro end end Test::Unit::TestCase.extend(GemMacro) shoulda-context-1.1.2/test/fake_rails_root/vendor/plugins/0000755000004100000410000000000012147161361023766 5ustar www-datawww-datashoulda-context-1.1.2/test/fake_rails_root/vendor/plugins/plugin_with_macro/0000755000004100000410000000000012147161361027500 5ustar www-datawww-datashoulda-context-1.1.2/test/fake_rails_root/vendor/plugins/plugin_with_macro/shoulda_macros/0000755000004100000410000000000012147161361032503 5ustar www-datawww-data././@LongLink0000000000000000000000000000015300000000000011564 Lustar rootrootshoulda-context-1.1.2/test/fake_rails_root/vendor/plugins/plugin_with_macro/shoulda_macros/plugin_macro.rbshoulda-context-1.1.2/test/fake_rails_root/vendor/plugins/plugin_with_macro/shoulda_macros/plugin_ma0000644000004100000410000000013212147161361034375 0ustar www-datawww-datamodule PluginMacro def plugin_macro end end Test::Unit::TestCase.extend(PluginMacro) shoulda-context-1.1.2/test/fake_rails_root/vendor/plugins/.keep0000644000004100000410000000000012147161361024701 0ustar www-datawww-datashoulda-context-1.1.2/test/shoulda/0000755000004100000410000000000012147161361017304 5ustar www-datawww-datashoulda-context-1.1.2/test/shoulda/helpers_test.rb0000644000004100000410000001332312147161361022334 0ustar www-datawww-datarequire 'test_helper' class HelpersTest < Test::Unit::TestCase # :nodoc: context "an array of values" do setup do @a = ['abc', 'def', 3] end [/b/, 'abc', 3].each do |x| should "contain #{x.inspect}" do assert_raises(Test::Unit::AssertionFailedError) do assert_does_not_contain @a, x end assert_contains @a, x end end should "not contain 'wtf'" do assert_raises(Test::Unit::AssertionFailedError) {assert_contains @a, 'wtf'} assert_does_not_contain @a, 'wtf' end should "be the same as another array, ordered differently" do assert_same_elements(@a, [3, "def", "abc"]) assert_raises(Test::Unit::AssertionFailedError) do assert_same_elements(@a, [3, 3, "def", "abc"]) end assert_same_elements([@a, "abc"].flatten, ["abc", 3, "def", "abc"]) assert_raises(Test::Unit::AssertionFailedError) do assert_same_elements([@a, "abc"].flatten, [3, 3, "def", "abc"]) end end should "only count the number of occurrences once for each unique value" do a1 = [@a, "abc"].flatten a1.expects(:select).times(3).returns(["abc", "abc"], ["def"], [3]) assert_same_elements(a1, ["abc", 3, "def", "abc"]) end end context "a matching matcher" do setup do @matcher = stub('matcher', :matches? => true, :failure_message_for_should => 'bad failure message', :failure_message_for_should_not => 'big time failure') end should "pass when given to assert_accepts with no message expectation" do assert_accepts @matcher, 'target' end should "pass when given to assert_accepts with a matching message" do assert_accepts @matcher, 'target', :message => /big time/ end should "fail when given to assert_accepts with non-matching message" do assert_raise Test::Unit::AssertionFailedError do assert_accepts @matcher, 'target', :message => /small time/ end end context "when given to assert_rejects" do context "and matcher has :does_not_match?" do setup do @error = nil begin @matcher.stubs(:matches?).returns(false) @matcher.stubs(:does_not_match?).returns(true) assert_rejects @matcher, 'target' rescue Test::Unit::AssertionFailedError => @error end end should "pass" do assert_nil @error end end context "and matcher does not have :does_not_match?" do setup do @error = nil begin assert_rejects @matcher, 'target' rescue Test::Unit::AssertionFailedError => @error end end should "fail" do assert_not_nil @error end should "use the error message from the matcher" do assert_equal 'big time failure', @error.message end end end end context "a non-matching matcher" do setup do @matcher = stub('matcher', :matches? => false, :failure_message_for_should => 'big time failure', :failure_message_for_should_not => 'bad failure message') end should "pass when given to assert_rejects with no message expectation" do assert_rejects @matcher, 'target' end should "pass when given to assert_rejects with a matching message" do assert_rejects @matcher, 'target', :message => /big time/ end should "fail when given to assert_rejects with a non-matching message" do assert_raise Test::Unit::AssertionFailedError do assert_rejects @matcher, 'target', :message => /small time/ end end context "when given to assert_accepts" do setup do begin assert_accepts @matcher, 'target' rescue Test::Unit::AssertionFailedError => @error end end should "fail" do assert_not_nil @error end should "use the error message from the matcher" do assert_equal 'big time failure', @error.message end end end context "a matcher using antiquated syntax" do setup do @matcher = stub('matcher', :matches? => false, :failure_message => 'big time failure', :negative_failure_message => 'bad failure message') end should "pass when given to assert_rejects with no message expectation" do assert_rejects @matcher, 'target' end should "pass when given to assert_rejects with a matching message" do assert_rejects @matcher, 'target', :message => /big time/ end should "fail when given to assert_rejects with a non-matching message" do assert_raise Test::Unit::AssertionFailedError do assert_rejects @matcher, 'target', :message => /small time/ end end context "when given to assert_accepts" do setup do begin assert_accepts @matcher, 'target' rescue Test::Unit::AssertionFailedError => @error end end should "fail" do assert_not_nil @error end should "use the error message from the matcher" do assert_equal 'big time failure', @error.message end end end should "assign context to a support matching on assert_accepts" do matcher = stub('matcher', :matches? => true) matcher.expects(:in_context).with(self) assert_accepts matcher, nil end should "assign context to a support matching on assert_rejects" do matcher = stub('matcher', :matches? => false) matcher.expects(:in_context).with(self) assert_rejects matcher, nil end end shoulda-context-1.1.2/test/shoulda/should_test.rb0000644000004100000410000001700412147161361022170 0ustar www-datawww-datarequire 'test_helper' class ShouldTest < Test::Unit::TestCase # :nodoc: should "be able to define a should statement outside of a context" do assert true end should "see the name of my class as ShouldTest" do assert_equal "ShouldTest", self.class.name end def self.should_see_class_methods should "be able to see class methods" do assert true end end def self.should_be_able_to_setup_a_should_eventually_in_a_class_method should "be able to setup a should eventually in a class method" end def self.should_see_a_context_block_like_a_Test_Unit_class should "see a context block as a Test::Unit class" do assert_equal "ShouldTest", self.class.name end end def self.should_see_blah should "see @blah through a macro" do assert @blah end end def self.should_not_see_blah should "not see @blah through a macro" do assert !instance_variable_defined?(:@blah) end end def self.should_be_able_to_make_context_macros(prefix = nil) context "a macro" do should "have the tests named correctly" do assert_match(/^test: #{prefix}a macro should have the tests named correctly/, self.to_s) end end end context "Context" do should_see_class_methods should_see_a_context_block_like_a_Test_Unit_class should_be_able_to_make_context_macros("Context ") should_be_able_to_setup_a_should_eventually_in_a_class_method should "not define @blah" do assert ! self.instance_variables.include?("@blah") end should_not_see_blah should "be able to define a should statement" do assert true end should "see the name of my class as ShouldTest" do assert_equal "ShouldTest", self.class.name end context "with a subcontext" do should_be_able_to_make_context_macros("Context with a subcontext ") end end context "Context with setup block" do setup do @blah = "blah" end should "have @blah == 'blah'" do assert_equal "blah", @blah end should_see_blah should "have name set right" do assert_match(/^test: Context with setup block/, self.to_s) end context "and a subcontext" do setup do @blah = "#{@blah} twice" end should "be named correctly" do assert_match(/^test: Context with setup block and a subcontext should be named correctly/, self.to_s) end should "run the setup methods in order" do assert_equal @blah, "blah twice" end should_see_blah end end context "Another context with setup block" do setup do @blah = "foo" end should "have @blah == 'foo'" do assert_equal "foo", @blah end should "have name set right" do assert_match(/^test: Another context with setup block/, self.to_s) end should_see_blah end should_eventually "pass, since it's a should_eventually" do flunk "what?" end # Context creation and naming def test_should_create_a_new_context assert_nothing_raised do Shoulda::Context::Context.new("context name", self) do; end end end def test_should_create_a_new_context_even_if_block_is_omitted old_verbose, $VERBOSE = $VERBOSE, nil assert_nothing_raised do Shoulda::Context::Context.new("context without a block", self) end ensure $VERBOSE = old_verbose end def test_should_create_a_nested_context assert_nothing_raised do parent = Shoulda::Context::Context.new("Parent", self) do; end child = Shoulda::Context::Context.new("Child", parent) do; end raise unless child.instance_of? Shoulda::Context::Context end end def test_should_name_a_contexts_correctly parent = Shoulda::Context::Context.new("Parent", self) do; end child = Shoulda::Context::Context.new("Child", parent) do; end grandchild = Shoulda::Context::Context.new("GrandChild", child) do; end assert_equal "Parent", parent.full_name assert_equal "Parent Child", child.full_name assert_equal "Parent Child GrandChild", grandchild.full_name end # Should statements def test_should_have_should_hashes_when_given_should_statements context = Shoulda::Context::Context.new("name", self) do should "be good" do; end should "another" do; end end names = context.shoulds.map {|s| s[:name]} assert_equal ["another", "be good"], names.sort end # setup and teardown def test_should_capture_setup_and_teardown_blocks context = Shoulda::Context::Context.new("name", self) do setup do; "setup"; end teardown do; "teardown"; end end assert_equal "setup", context.setup_blocks.first.call assert_equal "teardown", context.teardown_blocks.first.call end # building def test_should_create_shoulda_test_for_each_should_on_build context = Shoulda::Context::Context.new("name", self) do should "one" do; end should "two" do; end end context.expects(:create_test_from_should_hash).with(has_entry(:name => "one")) context.expects(:create_test_from_should_hash).with(has_entry(:name => "two")) context.build end def test_should_create_test_methods_on_build tu_class = Test::Unit::TestCase context = Shoulda::Context::Context.new("A Context", tu_class) do should "define the test" do; end end tu_class.expects(:define_method).with(:"test: A Context should define the test. ") context.build end def test_should_create_test_methods_on_build_when_subcontext tu_class = Test::Unit::TestCase context = Shoulda::Context::Context.new("A Context", tu_class) do context "with a child" do should "define the test" do; end end end tu_class.expects(:define_method).with(:"test: A Context with a child should define the test. ") context.build end # Test::Unit integration def test_should_create_a_new_context_and_build_it_on_Test_Unit_context c = mock("context") c.expects(:build) Shoulda::Context::Context.expects(:new).with("foo", kind_of(Class)).returns(c) self.class.context "foo" do; end end def test_should_create_a_one_off_context_and_build_it_on_Test_Unit_should s = mock("test") Shoulda::Context::Context.any_instance.expects(:should).with("rock", {}).returns(s) Shoulda::Context::Context.any_instance.expects(:build) self.class.should "rock" do; end end def test_should_create_a_one_off_context_and_build_it_on_Test_Unit_should_eventually s = mock("test") Shoulda::Context::Context.any_instance.expects(:should_eventually).with("rock").returns(s) Shoulda::Context::Context.any_instance.expects(:build) self.class.should_eventually "rock" do; end end should "run a :before proc", :before => lambda { @value = "before" } do assert_equal "before", @value end context "A :before proc" do setup do assert_equal "before", @value @value = "setup" end should "run before the current setup", :before => lambda { @value = "before" } do assert_equal "setup", @value end end context "a before statement" do setup do assert_equal "before", @value @value = "setup" end before_should "run before the current setup" do @value = "before" end end context "A context" do setup do @value = "outer" end context "with a subcontext and a :before proc" do before = lambda do assert "outer", @value @value = "before" end should "run after the parent setup", :before => before do assert_equal "before", @value end end end end shoulda-context-1.1.2/test/shoulda/autoload_macro_test.rb0000644000004100000410000000071312147161361023662 0ustar www-datawww-datarequire 'test_helper' class AutoloadMacroTest < Test::Unit::TestCase # :nodoc: context "The macro auto-loader" do should "load macros from the plugins" do assert self.class.respond_to?('plugin_macro') end should "load macros from the gems" do assert self.class.respond_to?('gem_macro') end should "load custom macros from ROOT/test/shoulda_macros" do assert self.class.respond_to?('custom_macro') end end end shoulda-context-1.1.2/test/shoulda/convert_to_should_syntax_test.rb0000644000004100000410000000243112147161361026036 0ustar www-datawww-datarequire 'test/unit' class ConvertToShouldSyntaxTest < Test::Unit::TestCase # :nodoc: BEFORE_FIXTURE = <<-EOS class DummyTest < Test::Unit::TestCase should "Not change this_word_with_underscores" do end def test_should_be_working assert true end def test_some_cool_stuff assert true end def non_test_method end end EOS AFTER_FIXTURE = <<-EOS class DummyTest < Test::Unit::TestCase should "Not change this_word_with_underscores" do end should "be working" do assert true end should "RENAME ME: test some cool stuff" do assert true end def non_test_method end end EOS FIXTURE_PATH = "./convert_to_should_syntax_fixture.dat" RUBY = ENV['RUBY'] || 'ruby' def test_convert_to_should_syntax File.open(FIXTURE_PATH, "w") {|f| f.write(BEFORE_FIXTURE)} cmd = "#{RUBY} #{File.join(File.dirname(__FILE__), '../../bin/convert_to_should_syntax')} #{FIXTURE_PATH}" output = `#{cmd}` File.unlink($1) if output.match(/has been stored in '([^']+)/) assert_match(/has been converted/, output) result = IO.read(FIXTURE_PATH) assert_equal result, AFTER_FIXTURE end def teardown File.unlink(FIXTURE_PATH) end end shoulda-context-1.1.2/test/shoulda/context_test.rb0000644000004100000410000002024212147161361022354 0ustar www-datawww-datarequire 'test_helper' class ContextTest < Test::Unit::TestCase # :nodoc: def self.context_macro(&blk) context "with a subcontext made by a macro" do setup { @context_macro = :foo } merge_block(&blk) end end context "context with setup block" do setup do @blah = "blah" end should "run the setup block" do assert_equal "blah", @blah end should "have name set right" do assert_match(/^test: context with setup block/, self.to_s) end context "and a subcontext" do setup do @blah = "#{@blah} twice" end should "be named correctly" do assert_match(/^test: context with setup block and a subcontext should be named correctly/, self.to_s) end should "run the setup blocks in order" do assert_equal @blah, "blah twice" end end context_macro do should "have name set right" do assert_match(/^test: context with setup block with a subcontext made by a macro should have name set right/, self.to_s) end should "run the setup block of that context macro" do assert_equal :foo, @context_macro end should "run the setup block of the main context" do assert_equal "blah", @blah end end end context "another context with setup block" do setup do @blah = "foo" end should "have @blah == 'foo'" do assert_equal "foo", @blah end should "have name set right" do assert_match(/^test: another context with setup block/, self.to_s) end end context "context with method definition" do setup do def hello; "hi"; end end should "be able to read that method" do assert_equal "hi", hello end should "have name set right" do assert_match(/^test: context with method definition/, self.to_s) end end context "another context" do should "not define @blah" do assert !instance_variable_defined?(:@blah) end end context "context with multiple setups and/or teardowns" do cleanup_count = 0 2.times do |i| setup { cleanup_count += 1 } teardown { cleanup_count -= 1 } end 2.times do |i| should "call all setups and all teardowns (check ##{i + 1})" do assert_equal 2, cleanup_count end end context "subcontexts" do 2.times do |i| setup { cleanup_count += 1 } teardown { cleanup_count -= 1 } end 2.times do |i| should "also call all setups and all teardowns in parent and subcontext (check ##{i + 1})" do assert_equal 4, cleanup_count end end end end should_eventually "pass, since it's unimplemented" do flunk "what?" end should_eventually "not require a block when using should_eventually" should "pass without a block, as that causes it to piggyback to should_eventually" context "context for testing should piggybacking" do should "call should_eventually as we are not passing a block" end context "context" do context "with nested subcontexts" do should_eventually "only print this statement once for a should_eventually" end end class ::SomeModel; end context "given a test named after a class" do setup do self.class.stubs(:name).returns("SomeModelTest") end should "determine the described type" do assert_equal SomeModel, self.class.described_type end should "return a new instance of the described type as the subject if none exists" do assert_kind_of SomeModel, subject end context "with an explicit subject block" do setup { @expected = SomeModel.new } subject { @expected } should "return the result of the block as the subject" do assert_equal @expected, subject end context "nested context block without a subject block" do should "return the result of the parent context's subject block" do assert_equal @expected, subject end end end end end class ::Some class NestedModel; end end class Some::NestedModelTest < Test::Unit::TestCase should "determine the described type for a nested model" do assert_equal Some::NestedModel, self.class.described_type end end class ShouldMatcherTest < Test::Unit::TestCase class FakeMatcher attr_reader :subject attr_accessor :fail def description "do something" end def matches?(subject) @subject = subject !@fail end def failure_message_for_should "failure message for should" end def failure_message_for_should_not "failure message for should not" end end def run_test_suite @test_suite.run(@test_result) { |event, name| } end def setup @matcher = FakeMatcher.new @test_result = Test::Unit::TestResult.new class << @test_result def failure_messages @failures.map { |failure| failure.message } end end end def create_test_suite(&definition) test_class = Class.new(Test::Unit::TestCase, &definition) test_class.suite end def assert_failed_with(message, test_result) assert_equal 1, test_result.failure_count assert_equal [message], test_result.failure_messages end def assert_passed(test_result) assert_equal 0, test_result.failure_count end def assert_test_named(expected_name, test_suite) name = test_suite.tests.map { |test| test.method_name }.first assert name.include?(expected_name), "Expected #{name} to include #{expected_name}" end def self.should_use_positive_matcher should "generate a test using the matcher's description" do assert_test_named "should #{@matcher.description}", @test_suite end should "pass with a passing matcher" do @matcher.fail = false run_test_suite assert_passed @test_result end should "fail with a failing matcher" do @matcher.fail = true run_test_suite assert_failed_with "failure message for should", @test_result end should "provide the subject" do @matcher.fail = false run_test_suite assert_equal 'a subject', @matcher.subject end end def self.should_use_negative_matcher should "generate a test using the matcher's description" do assert_test_named "should not #{@matcher.description}", @test_suite end should "pass with a failing matcher" do @matcher.fail = true run_test_suite assert_passed @test_result end should "fail with a passing matcher" do @matcher.fail = false run_test_suite assert_failed_with "failure message for should not", @test_result end should "provide the subject" do @matcher.fail = false run_test_suite assert_equal 'a subject', @matcher.subject end end context "a should block with a matcher" do setup do matcher = @matcher @test_suite = create_test_suite do subject { 'a subject' } should matcher end end should_use_positive_matcher end context "a should block with a matcher within a context" do setup do matcher = @matcher @test_suite = create_test_suite do context "in context" do subject { 'a subject' } should matcher end end end should_use_positive_matcher end context "a should_not block with a matcher" do setup do matcher = @matcher @test_suite = create_test_suite do subject { 'a subject' } should_not matcher end end should_use_negative_matcher end context "a should_not block with a matcher within a context" do setup do matcher = @matcher @test_suite = create_test_suite do context "in context" do subject { 'a subject' } should_not matcher end end end should_use_negative_matcher end end class Subject; end class SubjectTest < Test::Unit::TestCase def setup @expected = Subject.new end subject { @expected } should "return a specified subject" do assert_equal @expected, subject end end class SubjectLazinessTest < Test::Unit::TestCase subject { Subject.new } should "only build the subject once" do assert_equal subject, subject end end shoulda-context-1.1.2/test/test_helper.rb0000644000004100000410000000047712147161361020520 0ustar www-datawww-datarequire 'fileutils' require 'test/unit' require 'mocha' shoulda_path = File.join(File.dirname(__FILE__), '..', 'lib') $LOAD_PATH << shoulda_path require "shoulda/context" Shoulda.autoload_macros File.join(File.dirname(__FILE__), 'fake_rails_root'), File.join("vendor", "{plugins,gems}", "*") shoulda-context-1.1.2/tasks/0000755000004100000410000000000012147161361016013 5ustar www-datawww-datashoulda-context-1.1.2/tasks/shoulda.rake0000644000004100000410000000012612147161361020315 0ustar www-datawww-dataload File.join(File.dirname(__FILE__), "..", "lib", "shoulda", "context", "tasks.rb") shoulda-context-1.1.2/shoulda-context.gemspec0000644000004100000410000000220712147161361021355 0ustar www-datawww-data# -*- encoding: utf-8 -*- $LOAD_PATH << File.join(File.dirname(__FILE__), 'lib') require 'shoulda/context/version' Gem::Specification.new do |s| s.name = %q{shoulda-context} s.version = Shoulda::Context::VERSION.dup s.platform = Gem::Platform::RUBY s.authors = ["thoughtbot, inc.", "Tammer Saleh", "Joe Ferris", "Ryan McGeary", "Dan Croak", "Matt Jankowski"] s.email = %q{support@thoughtbot.com} s.homepage = %q{http://thoughtbot.com/community/} s.summary = %q{Context framework extracted from Shoulda} s.description = %q{Context framework extracted from Shoulda} s.license = %q{MIT} s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } s.require_paths = ["lib"] s.add_development_dependency("appraisal", "~> 0.5") s.add_development_dependency("rails", ">= 3.0") s.add_development_dependency("mocha", "~> 0.9.10") s.add_development_dependency("rake") s.add_development_dependency("test-unit", "~> 2.1.0") end shoulda-context-1.1.2/init.rb0000644000004100000410000000007312147161361016156 0ustar www-datawww-datarequire File.join(File.dirname(__FILE__), 'rails', 'init') shoulda-context-1.1.2/README.md0000644000004100000410000000401712147161361016147 0ustar www-datawww-data# shoulda-context [![Gem Version](https://badge.fury.io/rb/shoulda-context.png)](http://badge.fury.io/rb/shoulda-context) [![Build Status](https://travis-ci.org/thoughtbot/shoulda-context.png?branch=master)](https://travis-ci.org/thoughtbot/shoulda-context) [Official Documentation](http://rubydoc.info/github/thoughtbot/shoulda-context/master/frames) Shoulda's contexts make it easy to write understandable and maintainable tests for Test::Unit. It's fully compatible with your existing tests in Test::Unit, and requires no retooling to use. Refer to the [shoulda](https://github.com/thoughtbot/shoulda) gem if you want to know more about using shoulda with Rails or RSpec. ## Contexts Instead of writing Ruby methods with `lots_of_underscores`, shoulda-context adds context, setup, and should blocks... class CalculatorTest < Test::Unit::TestCase context "a calculator" do setup do @calculator = Calculator.new end should "add two numbers for the sum" do assert_equal 4, @calculator.sum(2, 2) end should "multiply two numbers for the product" do assert_equal 10, @calculator.product(2, 5) end end end ... which combine to produce the following test methods: "test: a calculator should add two numbers for the sum." "test: a calculator should multiply two numbers for the product." ## Assertions It also has two additional Test::Unit assertions for working with Ruby's Array: assert_same_elements([:a, :b, :c], [:c, :a, :b]) assert_contains(['a', '1'], /\d/) assert_contains(['a', '1'], 'a') ## Credits Shoulda is maintained and funded by [thoughtbot](http://thoughtbot.com/community). shoulda-context is maintained by [Travis Jeffery](https://github.com/travisjeffery). Thank you to all the [contributors](https://github.com/thoughtbot/shoulda-context/contributors). ## License Shoulda is Copyright © 2006-2013 thoughtbot, inc. It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file. shoulda-context-1.1.2/gemfiles/0000755000004100000410000000000012147161361016461 5ustar www-datawww-datashoulda-context-1.1.2/gemfiles/4.0.gemfile0000644000004100000410000000024512147161361020315 0ustar www-datawww-data# This file was generated by Appraisal source "http://rubygems.org" gem "rails", "4.0.0.rc1" gem "jquery-rails" gem "sass-rails", "4.0.0.rc1" gemspec :path=>"../"shoulda-context-1.1.2/gemfiles/3.1.gemfile.lock0000644000004100000410000000455112147161361021250 0ustar www-datawww-dataPATH remote: /Users/rmcgeary/work/oss/shoulda-context specs: shoulda-context (1.1.1) GEM remote: http://rubygems.org/ specs: actionmailer (3.1.8) actionpack (= 3.1.8) mail (~> 2.3.3) actionpack (3.1.8) activemodel (= 3.1.8) activesupport (= 3.1.8) builder (~> 3.0.0) erubis (~> 2.7.0) i18n (~> 0.6) rack (~> 1.3.6) rack-cache (~> 1.2) rack-mount (~> 0.8.2) rack-test (~> 0.6.1) sprockets (~> 2.0.4) activemodel (3.1.8) activesupport (= 3.1.8) builder (~> 3.0.0) i18n (~> 0.6) activerecord (3.1.8) activemodel (= 3.1.8) activesupport (= 3.1.8) arel (~> 2.2.3) tzinfo (~> 0.3.29) activeresource (3.1.8) activemodel (= 3.1.8) activesupport (= 3.1.8) activesupport (3.1.8) multi_json (>= 1.0, < 1.3) appraisal (0.5.2) bundler rake arel (2.2.3) builder (3.0.4) erubis (2.7.0) hike (1.2.2) i18n (0.6.4) jquery-rails (2.2.1) railties (>= 3.0, < 5.0) thor (>= 0.14, < 2.0) json (1.8.0) mail (2.3.3) i18n (>= 0.4.0) mime-types (~> 1.16) treetop (~> 1.4.8) mime-types (1.23) mocha (0.9.12) multi_json (1.2.0) polyglot (0.3.3) rack (1.3.10) rack-cache (1.2) rack (>= 0.4) rack-mount (0.8.3) rack (>= 1.0.0) rack-ssl (1.3.3) rack rack-test (0.6.2) rack (>= 1.0) rails (3.1.8) actionmailer (= 3.1.8) actionpack (= 3.1.8) activerecord (= 3.1.8) activeresource (= 3.1.8) activesupport (= 3.1.8) bundler (~> 1.0) railties (= 3.1.8) railties (3.1.8) actionpack (= 3.1.8) activesupport (= 3.1.8) rack-ssl (~> 1.3.2) rake (>= 0.8.7) rdoc (~> 3.4) thor (~> 0.14.6) rake (10.0.4) rdoc (3.12.2) json (~> 1.4) sass (3.2.9) sass-rails (3.1.0) actionpack (~> 3.1.0) railties (~> 3.1.0) sass (>= 3.1.4) sprockets (2.0.4) hike (~> 1.2) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) test-unit (2.1.2) thor (0.14.6) tilt (1.4.1) treetop (1.4.12) polyglot polyglot (>= 0.3.1) tzinfo (0.3.37) PLATFORMS ruby DEPENDENCIES appraisal (~> 0.5) jquery-rails mocha (~> 0.9.10) rails (= 3.1.8) rake sass-rails shoulda-context! test-unit (~> 2.1.0) shoulda-context-1.1.2/gemfiles/3.0.gemfile0000644000004100000410000000016112147161361020311 0ustar www-datawww-data# This file was generated by Appraisal source "http://rubygems.org" gem "rails", "3.0.17" gemspec :path=>"../"shoulda-context-1.1.2/gemfiles/3.0.gemfile.lock0000644000004100000410000000370012147161361021242 0ustar www-datawww-dataPATH remote: /Users/rmcgeary/work/oss/shoulda-context specs: shoulda-context (1.1.1) GEM remote: http://rubygems.org/ specs: abstract (1.0.0) actionmailer (3.0.17) actionpack (= 3.0.17) mail (~> 2.2.19) actionpack (3.0.17) activemodel (= 3.0.17) activesupport (= 3.0.17) builder (~> 2.1.2) erubis (~> 2.6.6) i18n (~> 0.5.0) rack (~> 1.2.5) rack-mount (~> 0.6.14) rack-test (~> 0.5.7) tzinfo (~> 0.3.23) activemodel (3.0.17) activesupport (= 3.0.17) builder (~> 2.1.2) i18n (~> 0.5.0) activerecord (3.0.17) activemodel (= 3.0.17) activesupport (= 3.0.17) arel (~> 2.0.10) tzinfo (~> 0.3.23) activeresource (3.0.17) activemodel (= 3.0.17) activesupport (= 3.0.17) activesupport (3.0.17) appraisal (0.5.2) bundler rake arel (2.0.10) builder (2.1.2) erubis (2.6.6) abstract (>= 1.0.0) i18n (0.5.0) json (1.8.0) mail (2.2.20) activesupport (>= 2.3.6) i18n (>= 0.4.0) mime-types (~> 1.16) treetop (~> 1.4.8) mime-types (1.23) mocha (0.9.12) polyglot (0.3.3) rack (1.2.8) rack-mount (0.6.14) rack (>= 1.0.0) rack-test (0.5.7) rack (>= 1.0) rails (3.0.17) actionmailer (= 3.0.17) actionpack (= 3.0.17) activerecord (= 3.0.17) activeresource (= 3.0.17) activesupport (= 3.0.17) bundler (~> 1.0) railties (= 3.0.17) railties (3.0.17) actionpack (= 3.0.17) activesupport (= 3.0.17) rake (>= 0.8.7) rdoc (~> 3.4) thor (~> 0.14.4) rake (10.0.4) rdoc (3.12.2) json (~> 1.4) test-unit (2.1.2) thor (0.14.6) treetop (1.4.12) polyglot polyglot (>= 0.3.1) tzinfo (0.3.37) PLATFORMS ruby DEPENDENCIES appraisal (~> 0.5) mocha (~> 0.9.10) rails (= 3.0.17) rake shoulda-context! test-unit (~> 2.1.0) shoulda-context-1.1.2/gemfiles/3.1.gemfile0000644000004100000410000000022412147161361020312 0ustar www-datawww-data# This file was generated by Appraisal source "http://rubygems.org" gem "rails", "3.1.8" gem "jquery-rails" gem "sass-rails" gemspec :path=>"../"shoulda-context-1.1.2/gemfiles/4.0.gemfile.lock0000644000004100000410000000470312147161361021247 0ustar www-datawww-dataPATH remote: /Users/rmcgeary/work/oss/shoulda-context specs: shoulda-context (1.1.1) GEM remote: http://rubygems.org/ specs: actionmailer (4.0.0.rc1) actionpack (= 4.0.0.rc1) mail (~> 2.5.3) actionpack (4.0.0.rc1) activesupport (= 4.0.0.rc1) builder (~> 3.1.0) erubis (~> 2.7.0) rack (~> 1.5.2) rack-test (~> 0.6.2) activemodel (4.0.0.rc1) activesupport (= 4.0.0.rc1) builder (~> 3.1.0) activerecord (4.0.0.rc1) activemodel (= 4.0.0.rc1) activerecord-deprecated_finders (~> 1.0.2) activesupport (= 4.0.0.rc1) arel (~> 4.0.0) activerecord-deprecated_finders (1.0.2) activesupport (4.0.0.rc1) i18n (~> 0.6, >= 0.6.4) minitest (~> 4.2) multi_json (~> 1.3) thread_safe (~> 0.1) tzinfo (~> 0.3.37) appraisal (0.5.2) bundler rake arel (4.0.0) atomic (1.1.9) builder (3.1.4) erubis (2.7.0) hike (1.2.2) i18n (0.6.4) jquery-rails (2.2.1) railties (>= 3.0, < 5.0) thor (>= 0.14, < 2.0) mail (2.5.3) i18n (>= 0.4.0) mime-types (~> 1.16) treetop (~> 1.4.8) mime-types (1.23) minitest (4.7.4) mocha (0.9.12) multi_json (1.7.3) polyglot (0.3.3) rack (1.5.2) rack-test (0.6.2) rack (>= 1.0) rails (4.0.0.rc1) actionmailer (= 4.0.0.rc1) actionpack (= 4.0.0.rc1) activerecord (= 4.0.0.rc1) activesupport (= 4.0.0.rc1) bundler (>= 1.3.0, < 2.0) railties (= 4.0.0.rc1) sprockets-rails (~> 2.0.0.rc4) railties (4.0.0.rc1) actionpack (= 4.0.0.rc1) activesupport (= 4.0.0.rc1) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) rake (10.0.4) sass (3.2.9) sass-rails (4.0.0.rc1) railties (>= 4.0.0.beta, < 5.0) sass (>= 3.1.10) sprockets-rails (~> 2.0.0.rc0) tilt (~> 1.3) sprockets (2.9.3) hike (~> 1.2) multi_json (~> 1.0) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) sprockets-rails (2.0.0.rc4) actionpack (>= 3.0) activesupport (>= 3.0) sprockets (~> 2.8) test-unit (2.1.2) thor (0.18.1) thread_safe (0.1.0) atomic tilt (1.4.1) treetop (1.4.12) polyglot polyglot (>= 0.3.1) tzinfo (0.3.37) PLATFORMS ruby DEPENDENCIES appraisal (~> 0.5) jquery-rails mocha (~> 0.9.10) rails (= 4.0.0.rc1) rake sass-rails (= 4.0.0.rc1) shoulda-context! test-unit (~> 2.1.0) shoulda-context-1.1.2/gemfiles/3.2.gemfile.lock0000644000004100000410000000451312147161361021247 0ustar www-datawww-dataPATH remote: /Users/rmcgeary/work/oss/shoulda-context specs: shoulda-context (1.1.1) GEM remote: http://rubygems.org/ specs: actionmailer (3.2.9) actionpack (= 3.2.9) mail (~> 2.4.4) actionpack (3.2.9) activemodel (= 3.2.9) activesupport (= 3.2.9) builder (~> 3.0.0) erubis (~> 2.7.0) journey (~> 1.0.4) rack (~> 1.4.0) rack-cache (~> 1.2) rack-test (~> 0.6.1) sprockets (~> 2.2.1) activemodel (3.2.9) activesupport (= 3.2.9) builder (~> 3.0.0) activerecord (3.2.9) activemodel (= 3.2.9) activesupport (= 3.2.9) arel (~> 3.0.2) tzinfo (~> 0.3.29) activeresource (3.2.9) activemodel (= 3.2.9) activesupport (= 3.2.9) activesupport (3.2.9) i18n (~> 0.6) multi_json (~> 1.0) appraisal (0.5.2) bundler rake arel (3.0.2) builder (3.0.4) erubis (2.7.0) hike (1.2.2) i18n (0.6.4) journey (1.0.4) jquery-rails (2.2.1) railties (>= 3.0, < 5.0) thor (>= 0.14, < 2.0) json (1.8.0) mail (2.4.4) i18n (>= 0.4.0) mime-types (~> 1.16) treetop (~> 1.4.8) mime-types (1.23) mocha (0.9.12) multi_json (1.7.3) polyglot (0.3.3) rack (1.4.5) rack-cache (1.2) rack (>= 0.4) rack-ssl (1.3.3) rack rack-test (0.6.2) rack (>= 1.0) rails (3.2.9) actionmailer (= 3.2.9) actionpack (= 3.2.9) activerecord (= 3.2.9) activeresource (= 3.2.9) activesupport (= 3.2.9) bundler (~> 1.0) railties (= 3.2.9) railties (3.2.9) actionpack (= 3.2.9) activesupport (= 3.2.9) rack-ssl (~> 1.3.2) rake (>= 0.8.7) rdoc (~> 3.4) thor (>= 0.14.6, < 2.0) rake (10.0.4) rdoc (3.12.2) json (~> 1.4) sass (3.2.9) sass-rails (3.2.6) railties (~> 3.2.0) sass (>= 3.1.10) tilt (~> 1.3) sprockets (2.2.2) hike (~> 1.2) multi_json (~> 1.0) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) test-unit (2.1.2) thor (0.18.1) tilt (1.4.1) treetop (1.4.12) polyglot polyglot (>= 0.3.1) tzinfo (0.3.37) PLATFORMS ruby DEPENDENCIES appraisal (~> 0.5) jquery-rails mocha (~> 0.9.10) rails (= 3.2.9) rake sass-rails shoulda-context! test-unit (~> 2.1.0) shoulda-context-1.1.2/gemfiles/3.2.gemfile0000644000004100000410000000022412147161361020313 0ustar www-datawww-data# This file was generated by Appraisal source "http://rubygems.org" gem "rails", "3.2.9" gem "jquery-rails" gem "sass-rails" gemspec :path=>"../"shoulda-context-1.1.2/Rakefile0000644000004100000410000000072212147161361016334 0ustar www-datawww-datarequire 'bundler/setup' require 'bundler/gem_tasks' require 'rake/testtask' require 'appraisal' $LOAD_PATH.unshift("lib") load 'tasks/shoulda.rake' Rake::TestTask.new do |t| t.libs << 'lib' << 'test' t.pattern = 'test/**/*_test.rb' t.verbose = false end desc 'Test the plugin under all supported Rails versions.' task :all => ['appraisal:cleanup', 'appraisal:install'] do exec('rake appraisal test') end desc 'Default: run tests' task :default => [:all] shoulda-context-1.1.2/rails/0000755000004100000410000000000012147161361016000 5ustar www-datawww-datashoulda-context-1.1.2/rails/init.rb0000644000004100000410000000021012147161361017261 0ustar www-datawww-dataif RAILS_ENV == 'test' require "shoulda/context" Shoulda.autoload_macros RAILS_ROOT, File.join("vendor", "{plugins,gems}", "*") end shoulda-context-1.1.2/Appraisals0000644000004100000410000000050112147161361016704 0ustar www-datawww-dataappraise '3.0' do gem 'rails', '3.0.17' end appraise '3.1' do gem 'rails', '3.1.8' gem 'jquery-rails' gem 'sass-rails' end appraise '3.2' do gem 'rails', '3.2.9' gem 'jquery-rails' gem 'sass-rails' end appraise '4.0' do gem 'rails', '4.0.0.rc1' gem 'jquery-rails' gem 'sass-rails', '4.0.0.rc1' end shoulda-context-1.1.2/bin/0000755000004100000410000000000012147161361015436 5ustar www-datawww-datashoulda-context-1.1.2/bin/convert_to_should_syntax0000755000004100000410000000250512147161361022534 0ustar www-datawww-data#!/usr/bin/env ruby require 'fileutils' require 'tmpdir' TMP = Dir::tmpdir def usage(msg = nil) puts "Error: #{msg}" if msg puts if msg puts "Usage: #{File.basename(__FILE__)} normal_test_file.rb" puts puts "Will convert an existing test file with names like " puts puts " def test_should_do_stuff" puts " ..." puts " end" puts puts "to one using the new syntax: " puts puts " should \"be super cool\" do" puts " ..." puts " end" puts puts "A copy of the old file will be left under #{TMP} in case\nthis script just seriously screws up" puts exit (msg ? 2 : 0) end usage("Wrong number of arguments.") unless ARGV.size == 1 usage("Temp directory '#{TMP}' is not valid. Set TMPDIR environment variable to a writeable directory.") unless File.directory?(TMP) && File.writable?(TMP) file = ARGV.shift tmpfile = File.join(TMP, File.basename(file)) usage("File '#{file}' doesn't exist") unless File.exists?(file) FileUtils.cp(file, tmpfile) contents = File.read(tmpfile) contents.gsub!(/def test_should_(\S+)/) {|line| "should \"#{$1.tr('_', ' ')}\" do"} contents.gsub!(/def test_(\S+)/) {|line| "should \"RENAME ME: test #{$1.tr('_', ' ')}\" do"} File.open(file, 'w') { |f| f.write(contents) } puts "File '#{file}' has been converted to 'should' syntax. Old version has been stored in '#{tmpfile}'" shoulda-context-1.1.2/checksums.yaml.gz0000444000004100000410000000065312147161361020160 0ustar www-datawww-data4QOk0޳_.Rdf!d=PE?|'aa'!i޼h~N-z: tE">\%{"+BqIAKbuG+;!j|Aw!(}x,jHl:Pbhg+b}@xq ۬n'YfTy. =[r덮ftƟTl13mR>喚Dџ@WErՄU,#䫃[P7QWLˠɤ - !ruby/object:Gem::Version version: '0.5' version_requirements: !ruby/object:Gem::Requirement requirements: - - ~> - !ruby/object:Gem::Version version: '0.5' type: :development prerelease: false name: appraisal - !ruby/object:Gem::Dependency requirement: !ruby/object:Gem::Requirement requirements: - - ! '>=' - !ruby/object:Gem::Version version: '3.0' version_requirements: !ruby/object:Gem::Requirement requirements: - - ! '>=' - !ruby/object:Gem::Version version: '3.0' type: :development prerelease: false name: rails - !ruby/object:Gem::Dependency requirement: !ruby/object:Gem::Requirement requirements: - - ~> - !ruby/object:Gem::Version version: 0.9.10 version_requirements: !ruby/object:Gem::Requirement requirements: - - ~> - !ruby/object:Gem::Version version: 0.9.10 type: :development prerelease: false name: mocha - !ruby/object:Gem::Dependency requirement: !ruby/object:Gem::Requirement requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' version_requirements: !ruby/object:Gem::Requirement requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' type: :development prerelease: false name: rake - !ruby/object:Gem::Dependency requirement: !ruby/object:Gem::Requirement requirements: - - ~> - !ruby/object:Gem::Version version: 2.1.0 version_requirements: !ruby/object:Gem::Requirement requirements: - - ~> - !ruby/object:Gem::Version version: 2.1.0 type: :development prerelease: false name: test-unit description: Context framework extracted from Shoulda email: support@thoughtbot.com executables: - convert_to_should_syntax extensions: [] extra_rdoc_files: [] files: - .gitignore - .travis.yml - Appraisals - CONTRIBUTING.md - Gemfile - MIT-LICENSE - README.md - Rakefile - bin/convert_to_should_syntax - gemfiles/3.0.gemfile - gemfiles/3.0.gemfile.lock - gemfiles/3.1.gemfile - gemfiles/3.1.gemfile.lock - gemfiles/3.2.gemfile - gemfiles/3.2.gemfile.lock - gemfiles/4.0.gemfile - gemfiles/4.0.gemfile.lock - init.rb - lib/shoulda-context.rb - lib/shoulda/context.rb - lib/shoulda/context/assertions.rb - lib/shoulda/context/autoload_macros.rb - lib/shoulda/context/context.rb - lib/shoulda/context/proc_extensions.rb - lib/shoulda/context/tasks.rb - lib/shoulda/context/tasks/list_tests.rake - lib/shoulda/context/tasks/yaml_to_shoulda.rake - lib/shoulda/context/version.rb - rails/init.rb - shoulda-context.gemspec - tasks/shoulda.rake - test/fake_rails_root/test/shoulda_macros/custom_macro.rb - test/fake_rails_root/vendor/gems/gem_with_macro-0.0.1/shoulda_macros/gem_macro.rb - test/fake_rails_root/vendor/plugins/.keep - test/fake_rails_root/vendor/plugins/plugin_with_macro/shoulda_macros/plugin_macro.rb - test/shoulda/autoload_macro_test.rb - test/shoulda/context_test.rb - test/shoulda/convert_to_should_syntax_test.rb - test/shoulda/helpers_test.rb - test/shoulda/should_test.rb - test/test_helper.rb homepage: http://thoughtbot.com/community/ licenses: - MIT metadata: {} post_install_message: rdoc_options: [] require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' required_rubygems_version: !ruby/object:Gem::Requirement requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' requirements: [] rubyforge_project: rubygems_version: 2.0.3 signing_key: specification_version: 4 summary: Context framework extracted from Shoulda test_files: - test/fake_rails_root/test/shoulda_macros/custom_macro.rb - test/fake_rails_root/vendor/gems/gem_with_macro-0.0.1/shoulda_macros/gem_macro.rb - test/fake_rails_root/vendor/plugins/.keep - test/fake_rails_root/vendor/plugins/plugin_with_macro/shoulda_macros/plugin_macro.rb - test/shoulda/autoload_macro_test.rb - test/shoulda/context_test.rb - test/shoulda/convert_to_should_syntax_test.rb - test/shoulda/helpers_test.rb - test/shoulda/should_test.rb - test/test_helper.rb shoulda-context-1.1.2/Gemfile0000644000004100000410000000004612147161361016161 0ustar www-datawww-datasource 'http://rubygems.org' gemspec shoulda-context-1.1.2/.gitignore0000644000004100000410000000012412147161361016653 0ustar www-datawww-data.bundle Gemfile.lock vendor/ruby vendor/cache doc coverage pkg *.swp *.swo tags tmp shoulda-context-1.1.2/lib/0000755000004100000410000000000012147161361015434 5ustar www-datawww-datashoulda-context-1.1.2/lib/shoulda-context.rb0000644000004100000410000000003212147161361021075 0ustar www-datawww-datarequire "shoulda/context" shoulda-context-1.1.2/lib/shoulda/0000755000004100000410000000000012147161361017073 5ustar www-datawww-datashoulda-context-1.1.2/lib/shoulda/context.rb0000644000004100000410000000160412147161361021105 0ustar www-datawww-databegin # if present, then also loads MiniTest::Unit::TestCase ActiveSupport::TestCase rescue end if defined?([ActiveSupport::TestCase, MiniTest::Unit::TestCase]) && (ActiveSupport::TestCase.ancestors.include?(MiniTest::Unit::TestCase)) base_test_case = MiniTest::Unit::TestCase else if !defined?(Test::Unit::TestCase) require 'test/unit/testcase' end base_test_case = Test::Unit::TestCase end require 'shoulda/context/version' require 'shoulda/context/proc_extensions' require 'shoulda/context/assertions' require 'shoulda/context/context' require 'shoulda/context/autoload_macros' module ShouldaContextLoadable def self.included(base) base.class_eval do include Shoulda::Context::Assertions include Shoulda::Context::InstanceMethods end base.extend(Shoulda::Context::ClassMethods) end end base_test_case.class_eval { include ShouldaContextLoadable } shoulda-context-1.1.2/lib/shoulda/context/0000755000004100000410000000000012147161361020557 5ustar www-datawww-datashoulda-context-1.1.2/lib/shoulda/context/version.rb0000644000004100000410000000010712147161361022567 0ustar www-datawww-datamodule Shoulda module Context VERSION = '1.1.2'.freeze end end shoulda-context-1.1.2/lib/shoulda/context/tasks/0000755000004100000410000000000012147161361021704 5ustar www-datawww-datashoulda-context-1.1.2/lib/shoulda/context/tasks/yaml_to_shoulda.rake0000644000004100000410000000161312147161361025734 0ustar www-datawww-datanamespace :shoulda do # From http://blog.internautdesign.com/2007/11/2/a-yaml_to_shoulda-rake-task # David.Lowenfels@gmail.com desc "Converts a YAML file (FILE=./path/to/yaml) into a Shoulda skeleton" task :from_yaml do require 'yaml' def yaml_to_context(hash, indent = 0) indent1 = ' ' * indent indent2 = ' ' * (indent + 1) hash.each_pair do |context, shoulds| puts indent1 + "context \"#{context}\" do" puts shoulds.each do |should| yaml_to_context( should, indent + 1 ) and next if should.is_a?( Hash ) puts indent2 + "should_eventually \"" + should.gsub(/^should +/,'') + "\" do" puts indent2 + "end" puts end puts indent1 + "end" end end puts("Please pass in a FILE argument.") and exit unless ENV['FILE'] yaml_to_context( YAML.load_file( ENV['FILE'] ) ) end end shoulda-context-1.1.2/lib/shoulda/context/tasks/list_tests.rake0000644000004100000410000000150412147161361024745 0ustar www-datawww-datanamespace :shoulda do desc "List the names of the test methods in a specification like format" task :list do $LOAD_PATH.unshift("test") require 'test/unit' require 'rubygems' require 'active_support' # bug in test unit. Set to true to stop from running. Test::Unit.run = true test_files = Dir.glob(File.join('test', '**', '*_test.rb')) test_files.each do |file| load file klass = File.basename(file, '.rb').classify unless Object.const_defined?(klass.to_s) puts "Skipping #{klass} because it doesn't map to a Class" next end klass = klass.constantize puts klass.name.gsub('Test', '') test_methods = klass.instance_methods.grep(/^test/).map {|s| s.gsub(/^test: /, '')}.sort test_methods.each {|m| puts " " + m } end end end shoulda-context-1.1.2/lib/shoulda/context/assertions.rb0000644000004100000410000000725012147161361023302 0ustar www-datawww-datamodule Shoulda # :nodoc: module Context module Assertions # Asserts that two arrays contain the same elements, the same number of times. Essentially ==, but unordered. # # assert_same_elements([:a, :b, :c], [:c, :a, :b]) => passes def assert_same_elements(a1, a2, msg = nil) [:select, :inject, :size].each do |m| [a1, a2].each {|a| assert_respond_to(a, m, "Are you sure that #{a.inspect} is an array? It doesn't respond to #{m}.") } end assert a1h = a1.inject({}) { |h,e| h[e] ||= a1.select { |i| i == e }.size; h } assert a2h = a2.inject({}) { |h,e| h[e] ||= a2.select { |i| i == e }.size; h } assert_equal(a1h, a2h, msg) end # Asserts that the given collection contains item x. If x is a regular expression, ensure that # at least one element from the collection matches x. +extra_msg+ is appended to the error message if the assertion fails. # # assert_contains(['a', '1'], /\d/) => passes # assert_contains(['a', '1'], 'a') => passes # assert_contains(['a', '1'], /not there/) => fails def assert_contains(collection, x, extra_msg = "") collection = Array(collection) msg = "#{x.inspect} not found in #{collection.to_a.inspect} #{extra_msg}" case x when Regexp assert(collection.detect { |e| e =~ x }, msg) else assert(collection.include?(x), msg) end end # Asserts that the given collection does not contain item x. If x is a regular expression, ensure that # none of the elements from the collection match x. def assert_does_not_contain(collection, x, extra_msg = "") collection = Array(collection) msg = "#{x.inspect} found in #{collection.to_a.inspect} " + extra_msg case x when Regexp assert(!collection.detect { |e| e =~ x }, msg) else assert(!collection.include?(x), msg) end end # Asserts that the given matcher returns true when +target+ is passed to #matches? def assert_accepts(matcher, target, options = {}) if matcher.respond_to?(:in_context) matcher.in_context(self) end if matcher.matches?(target) assert_block { true } if options[:message] message = matcher.respond_to?(:failure_message_for_should_not) ? matcher.failure_message_for_should_not : matcher.negative_failure_message assert_match options[:message], message end else message = matcher.respond_to?(:failure_message_for_should) ? matcher.failure_message_for_should : matcher.failure_message assert_block(message) { false } end end # Asserts that the given matcher returns true when +target+ is passed to #does_not_match? # or false when +target+ is passed to #matches? if #does_not_match? is not implemented def assert_rejects(matcher, target, options = {}) if matcher.respond_to?(:in_context) matcher.in_context(self) end not_match = matcher.respond_to?(:does_not_match?) ? matcher.does_not_match?(target) : !matcher.matches?(target) if not_match assert_block { true } if options[:message] message = matcher.respond_to?(:failure_message_for_should) ? matcher.failure_message_for_should : matcher.failure_message assert_match options[:message], message end else message = matcher.respond_to?(:failure_message_for_should_not) ? matcher.failure_message_for_should_not : matcher.negative_failure_message assert_block(message) { false } end end end end end shoulda-context-1.1.2/lib/shoulda/context/context.rb0000644000004100000410000003341612147161361022577 0ustar www-datawww-datamodule Shoulda module Context class << self def contexts # :nodoc: @contexts ||= [] end attr_writer :contexts def current_context # :nodoc: self.contexts.last end def add_context(context) # :nodoc: self.contexts.push(context) end def remove_context # :nodoc: self.contexts.pop end end module ClassMethods # == Should statements # # Should statements are just syntactic sugar over normal Test::Unit test # methods. A should block contains all the normal code and assertions # you're used to seeing, with the added benefit that they can be wrapped # inside context blocks (see below). # # === Example: # # class UserTest < Test::Unit::TestCase # # def setup # @user = User.new("John", "Doe") # end # # should "return its full name" # assert_equal 'John Doe', @user.full_name # end # # end # # ...will produce the following test: # * "test: User should return its full name. " # # Note: The part before should in the test name is gleamed from the name of the Test::Unit class. # # Should statements can also take a Proc as a :before option. This proc runs after any # parent context's setups but before the current context's setup. # # === Example: # # context "Some context" do # setup { puts("I run after the :before proc") } # # should "run a :before proc", :before => lambda { puts("I run before the setup") } do # assert true # end # end # # Should statements can also wrap matchers, making virtually any matcher # usable in a macro style. The matcher's description is used to generate a # test name and failure message, and the test will pass if the matcher # matches the subject. # # === Example: # # should validate_presence_of(:first_name).with_message(/gotta be there/) # def should(name_or_matcher, options = {}, &blk) if Shoulda::Context.current_context Shoulda::Context.current_context.should(name_or_matcher, options, &blk) else context_name = self.name.gsub(/Test/, "") if self.name context = Shoulda::Context::Context.new(context_name, self) do should(name_or_matcher, options, &blk) end context.build end end # Allows negative tests using matchers. The matcher's description is used # to generate a test name and negative failure message, and the test will # pass unless the matcher matches the subject. # # === Example: # # should_not set_the_flash def should_not(matcher) if Shoulda::Context.current_context Shoulda::Context.current_context.should_not(matcher) else context_name = self.name.gsub(/Test/, "") if self.name context = Shoulda::Context::Context.new(context_name, self) do should_not(matcher) end context.build end end # == Before statements # # Before statements are should statements that run before the current # context's setup. These are especially useful when setting expectations. # # === Example: # # class UserControllerTest < Test::Unit::TestCase # context "the index action" do # setup do # @users = [Factory(:user)] # User.stubs(:find).returns(@users) # end # # context "on GET" do # setup { get :index } # # should respond_with(:success) # # # runs before "get :index" # before_should "find all users" do # User.expects(:find).with(:all).returns(@users) # end # end # end # end def before_should(name, &blk) should(name, :before => blk) { assert true } end # Just like should, but never runs, and instead prints an 'X' in the Test::Unit output. def should_eventually(name, options = {}, &blk) context_name = self.name.gsub(/Test/, "") context = Shoulda::Context::Context.new(context_name, self) do should_eventually(name, &blk) end context.build end # == Contexts # # A context block groups should statements under a common set of setup/teardown methods. # Context blocks can be arbitrarily nested, and can do wonders for improving the maintainability # and readability of your test code. # # A context block can contain setup, should, should_eventually, and teardown blocks. # # class UserTest < Test::Unit::TestCase # context "A User instance" do # setup do # @user = User.find(:first) # end # # should "return its full name" # assert_equal 'John Doe', @user.full_name # end # end # end # # This code will produce the method "test: A User instance should return its full name. ". # # Contexts may be nested. Nested contexts run their setup blocks from out to in before each # should statement. They then run their teardown blocks from in to out after each should statement. # # class UserTest < Test::Unit::TestCase # context "A User instance" do # setup do # @user = User.find(:first) # end # # should "return its full name" # assert_equal 'John Doe', @user.full_name # end # # context "with a profile" do # setup do # @user.profile = Profile.find(:first) # end # # should "return true when sent :has_profile?" # assert @user.has_profile? # end # end # end # end # # This code will produce the following methods # * "test: A User instance should return its full name. " # * "test: A User instance with a profile should return true when sent :has_profile?. " # # Just like should statements, a context block can exist next to normal def test_the_old_way; end # tests. This means you do not have to fully commit to the context/should syntax in a test file. def context(name, &blk) if Shoulda::Context.current_context Shoulda::Context.current_context.context(name, &blk) else context = Shoulda::Context::Context.new(name, self, &blk) context.build end end # Returns the class being tested, as determined by the test class name. # # class UserTest; described_type; end # # => User def described_type @described_type ||= self.name. gsub(/Test$/, ''). split('::'). inject(Object) { |parent, local_name| parent.const_get(local_name) } end # Sets the return value of the subject instance method: # # class UserTest < Test::Unit::TestCase # subject { User.first } # # # uses the existing user # should validate_uniqueness_of(:email) # end def subject(&block) @subject_block = block end def subject_block # :nodoc: @subject_block ||= nil end end module InstanceMethods # Returns an instance of the class under test. # # class UserTest # should "be a user" do # assert_kind_of User, subject # passes # end # end # # The subject can be explicitly set using the subject class method: # # class UserTest # subject { User.first } # should "be an existing user" do # assert !subject.new_record? # uses the first user # end # end # # The subject is used by all macros that require an instance of the class # being tested. def subject @shoulda_subject ||= construct_subject end def subject_block # :nodoc: (@shoulda_context && @shoulda_context.subject_block) || self.class.subject_block end def get_instance_of(object_or_klass) # :nodoc: if object_or_klass.is_a?(Class) object_or_klass.new else object_or_klass end end def instance_variable_name_for(klass) # :nodoc: klass.to_s.split('::').last.underscore end private def construct_subject if subject_block instance_eval(&subject_block) else get_instance_of(self.class.described_type) end end end class Context # :nodoc: attr_accessor :name # my name attr_accessor :parent # may be another context, or the original test::unit class. attr_accessor :subcontexts # array of contexts nested under myself attr_accessor :setup_blocks # blocks given via setup methods attr_accessor :teardown_blocks # blocks given via teardown methods attr_accessor :shoulds # array of hashes representing the should statements attr_accessor :should_eventuallys # array of hashes representing the should eventually statements # accessor with cache def subject_block return @subject_block if @subject_block parent.subject_block end attr_writer :subject_block def initialize(name, parent, &blk) Shoulda::Context.add_context(self) self.name = name self.parent = parent self.setup_blocks = [] self.teardown_blocks = [] self.shoulds = [] self.should_eventuallys = [] self.subcontexts = [] self.subject_block = nil if block_given? merge_block(&blk) else merge_block { warn " * WARNING: Block missing for context '#{full_name}'" } end Shoulda::Context.remove_context end def merge_block(&blk) blk.bind(self).call end def context(name, &blk) self.subcontexts << Context.new(name, self, &blk) end def setup(&blk) self.setup_blocks << blk end def teardown(&blk) self.teardown_blocks << blk end def should(name_or_matcher, options = {}, &blk) if name_or_matcher.respond_to?(:description) && name_or_matcher.respond_to?(:matches?) name = name_or_matcher.description blk = lambda { assert_accepts name_or_matcher, subject } else name = name_or_matcher end if blk self.shoulds << { :name => name, :before => options[:before], :block => blk } else self.should_eventuallys << { :name => name } end end def should_not(matcher) name = matcher.description blk = lambda { assert_rejects matcher, subject } self.shoulds << { :name => "not #{name}", :block => blk } end def should_eventually(name, &blk) self.should_eventuallys << { :name => name, :block => blk } end def subject(&block) self.subject_block = block end def full_name parent_name = parent.full_name if am_subcontext? return [parent_name, name].join(" ").strip end def am_subcontext? parent.is_a?(self.class) # my parent is the same class as myself. end def test_unit_class am_subcontext? ? parent.test_unit_class : parent end def test_methods @test_methods ||= Hash.new { |h,k| h[k] = Hash[k.instance_methods.map { |n| [n, true] }] } end def create_test_from_should_hash(should) test_name = ["test:", full_name, "should", "#{should[:name]}. "].flatten.join(' ').to_sym if test_methods[test_unit_class][test_name.to_s] then warn " * WARNING: '#{test_name}' is already defined" end test_methods[test_unit_class][test_name.to_s] = true context = self test_unit_class.send(:define_method, test_name) do @shoulda_context = context begin context.run_parent_setup_blocks(self) should[:before].bind(self).call if should[:before] context.run_current_setup_blocks(self) should[:block].bind(self).call ensure context.run_all_teardown_blocks(self) end end end def run_all_setup_blocks(binding) run_parent_setup_blocks(binding) run_current_setup_blocks(binding) end def run_parent_setup_blocks(binding) self.parent.run_all_setup_blocks(binding) if am_subcontext? end def run_current_setup_blocks(binding) setup_blocks.each do |setup_block| setup_block.bind(binding).call end end def run_all_teardown_blocks(binding) teardown_blocks.reverse.each do |teardown_block| teardown_block.bind(binding).call end self.parent.run_all_teardown_blocks(binding) if am_subcontext? end def print_should_eventuallys should_eventuallys.each do |should| test_name = [full_name, "should", "#{should[:name]}. "].flatten.join(' ') puts " * DEFERRED: " + test_name end end def build shoulds.each do |should| create_test_from_should_hash(should) end subcontexts.each { |context| context.build } print_should_eventuallys end def method_missing(method, *args, &blk) test_unit_class.send(method, *args, &blk) end end end end shoulda-context-1.1.2/lib/shoulda/context/tasks.rb0000644000004100000410000000012312147161361022225 0ustar www-datawww-dataDir[File.join(File.dirname(__FILE__), 'tasks', '*.rake')].each do |f| load f end shoulda-context-1.1.2/lib/shoulda/context/proc_extensions.rb0000644000004100000410000000056512147161361024334 0ustar www-datawww-data# Stolen straight from ActiveSupport class Proc #:nodoc: def bind(object) block, time = self, Time.now (class << object; self end).class_eval do method_name = "__bind_#{time.to_i}_#{time.usec}" define_method(method_name, &block) method = instance_method(method_name) remove_method(method_name) method end.bind(object) end end shoulda-context-1.1.2/lib/shoulda/context/autoload_macros.rb0000644000004100000410000000361012147161361024260 0ustar www-datawww-datamodule Shoulda # :nodoc: # Call autoload_macros when you want to load test macros automatically in a non-Rails # project (it's done automatically for Rails projects). # You don't need to specify ROOT/test/shoulda_macros explicitly. Your custom macros # are loaded automatically when you call autoload_macros. # # The first argument is the path to you application's root directory. # All following arguments are directories relative to your root, which contain # shoulda_macros subdirectories. These directories support the same kinds of globs as the # Dir class. # # Basic usage (from a test_helper): # Shoulda.autoload_macros(File.dirname(__FILE__) + '/..') # will load everything in # - your_app/test/shoulda_macros # # To load vendored macros as well: # Shoulda.autoload_macros(APP_ROOT, 'vendor/*') # will load everything in # - APP_ROOT/vendor/*/shoulda_macros # - APP_ROOT/test/shoulda_macros # # To load macros in an app with a vendor directory laid out like Rails': # Shoulda.autoload_macros(APP_ROOT, 'vendor/{plugins,gems}/*') # or # Shoulda.autoload_macros(APP_ROOT, 'vendor/plugins/*', 'vendor/gems/*') # will load everything in # - APP_ROOT/vendor/plugins/*/shoulda_macros # - APP_ROOT/vendor/gems/*/shoulda_macros # - APP_ROOT/test/shoulda_macros # # If you prefer to stick testing dependencies away from your production dependencies: # Shoulda.autoload_macros(APP_ROOT, 'vendor/*', 'test/vendor/*') # will load everything in # - APP_ROOT/vendor/*/shoulda_macros # - APP_ROOT/test/vendor/*/shoulda_macros # - APP_ROOT/test/shoulda_macros def self.autoload_macros(root, *dirs) dirs << File.join('test') complete_dirs = dirs.map{|d| File.join(root, d, 'shoulda_macros')} all_files = complete_dirs.inject([]){ |files, dir| files + Dir[File.join(dir, '*.rb')] } all_files.each do |file| require file end end end