From 7b97dae9dcc88a0b6b6db3033f3c406b3662da6e Mon Sep 17 00:00:00 2001 From: HugoLnx Date: Fri, 25 Mar 2011 22:06:07 -0300 Subject: [PATCH] routing describe support request hash pair in description --- Gemfile-master.lock | 208 ++++++++++++++++++ .../routing_specs/route_to_matcher.feature | 15 ++ .../rails/example/routing_example_group.rb | 3 + .../describe_with_request_pair_support.rb | 21 ++ .../request_pair.rb | 21 ++ lib/rspec/rails/extensions.rb | 1 + lib/rspec/rails/extensions/ruby/.hash.rb.swo | Bin 0 -> 12288 bytes lib/rspec/rails/extensions/ruby/.hash.rb.swp | Bin 0 -> 12288 bytes lib/rspec/rails/extensions/ruby/hash.rb | 18 ++ .../request_pair_spec.rb | 20 ++ .../example/routing_example_group_spec.rb | 20 ++ spec/rspec/rails/extensions/ruby/hash_spec.rb | 23 ++ 12 files changed, 350 insertions(+) create mode 100644 Gemfile-master.lock create mode 100644 lib/rspec/rails/example/routing_example_group/describe_with_request_pair_support.rb create mode 100644 lib/rspec/rails/example/routing_example_group/describe_with_request_pair_support/request_pair.rb create mode 100644 lib/rspec/rails/extensions/ruby/.hash.rb.swo create mode 100644 lib/rspec/rails/extensions/ruby/.hash.rb.swp create mode 100644 lib/rspec/rails/extensions/ruby/hash.rb create mode 100644 spec/rspec/rails/example/routing_example_group/describe_with_request_pair_support/request_pair_spec.rb create mode 100644 spec/rspec/rails/extensions/ruby/hash_spec.rb diff --git a/Gemfile-master.lock b/Gemfile-master.lock new file mode 100644 index 0000000000..22c53bfae8 --- /dev/null +++ b/Gemfile-master.lock @@ -0,0 +1,208 @@ +GIT + remote: https://github.com/rack/rack.git + revision: b81080be0e5b3e9a794aa56609083b5d9dc90c3b + specs: + rack (1.2.1) + +GIT + remote: https://github.com/rails/arel.git + revision: 2b27e653f7be7649f56b834543bcaf27e2b44c74 + specs: + arel (2.0.7.beta.20110228092631) + +GIT + remote: https://github.com/rails/rails.git + revision: 9772de8d459960cc114c5b214343b7ce08fea21c + specs: + actionmailer (3.1.0.beta) + actionpack (= 3.1.0.beta) + mail (~> 2.2.15) + actionpack (3.1.0.beta) + activemodel (= 3.1.0.beta) + activesupport (= 3.1.0.beta) + builder (~> 3.0.0) + erubis (~> 2.6.6) + i18n (~> 0.5.0) + rack (~> 1.2.1) + rack-cache (~> 1.0.0) + rack-mount (~> 0.6.13) + rack-test (~> 0.5.7) + tzinfo (~> 0.3.23) + activemodel (3.1.0.beta) + activesupport (= 3.1.0.beta) + bcrypt-ruby (~> 2.1.4) + builder (~> 3.0.0) + i18n (~> 0.5.0) + activerecord (3.1.0.beta) + activemodel (= 3.1.0.beta) + activesupport (= 3.1.0.beta) + arel (~> 2.0.2) + tzinfo (~> 0.3.23) + activeresource (3.1.0.beta) + activemodel (= 3.1.0.beta) + activesupport (= 3.1.0.beta) + activesupport (3.1.0.beta) + rails (3.1.0.beta) + actionmailer (= 3.1.0.beta) + actionpack (= 3.1.0.beta) + activerecord (= 3.1.0.beta) + activeresource (= 3.1.0.beta) + activesupport (= 3.1.0.beta) + bundler (~> 1.0) + railties (= 3.1.0.beta) + railties (3.1.0.beta) + actionpack (= 3.1.0.beta) + activesupport (= 3.1.0.beta) + rake (>= 0.8.7) + thor (~> 0.14.4) + +PATH + remote: /home/hugolnx/programacao/projetos/ruby/open_sources/rspec-dev/repos/rspec + specs: + rspec (2.5.0) + rspec-core (~> 2.5.0) + rspec-expectations (~> 2.5.0) + rspec-mocks (~> 2.5.0) + +PATH + remote: /home/hugolnx/programacao/projetos/ruby/open_sources/rspec-dev/repos/rspec-core + specs: + rspec-core (2.5.1) + +PATH + remote: /home/hugolnx/programacao/projetos/ruby/open_sources/rspec-dev/repos/rspec-expectations + specs: + rspec-expectations (2.5.0) + diff-lcs (~> 1.1.2) + +PATH + remote: /home/hugolnx/programacao/projetos/ruby/open_sources/rspec-dev/repos/rspec-mocks + specs: + rspec-mocks (2.5.0) + +PATH + remote: . + specs: + rspec-rails (2.5.0) + actionpack (~> 3.0) + activesupport (~> 3.0) + railties (~> 3.0) + rspec (~> 2.5.0) + +GEM + remote: http://rubygems.org/ + specs: + ZenTest (4.4.2) + abstract (1.0.0) + archive-tar-minitar (0.5.2) + aruba (0.2.2) + bcrypt-ruby (2.1.4) + builder (3.0.0) + columnize (0.3.2) + configuration (1.2.0) + cucumber (0.10.0) + builder (>= 2.1.2) + diff-lcs (~> 1.1.2) + gherkin (~> 2.3.2) + json (~> 1.4.6) + term-ansicolor (~> 1.0.5) + diff-lcs (1.1.2) + erubis (2.6.6) + abstract (>= 1.0.0) + gherkin (2.3.5) + json (>= 1.4.6) + growl (1.0.3) + guard (0.3.0) + open_gem (~> 1.4.2) + thor (~> 0.14.6) + guard-rspec (0.1.9) + guard (>= 0.2.2) + i18n (0.5.0) + json (1.4.6) + launchy (0.3.7) + configuration (>= 0.0.5) + rake (>= 0.8.1) + linecache (0.43) + linecache19 (0.5.11) + ruby_core_source (>= 0.1.4) + mail (2.2.15) + activesupport (>= 2.3.6) + i18n (>= 0.4.0) + mime-types (~> 1.16) + treetop (~> 1.4.8) + mime-types (1.16) + nokogiri (1.4.4) + open_gem (1.4.2) + launchy (~> 0.3.5) + polyglot (0.3.1) + rack-cache (1.0) + rack (>= 0.4) + rack-mount (0.6.14) + rack (>= 1.0.0) + rack-test (0.5.7) + rack (>= 1.0) + rake (0.8.7) + rb-fsevent (0.3.10) + rcov (0.9.9) + relish (0.2.0) + archive-tar-minitar (~> 0.5.2) + json (~> 1.4.6) + rest-client (~> 1.6.1) + rest-client (1.6.1) + mime-types (>= 1.16) + ruby-debug (0.10.4) + columnize (>= 0.1) + ruby-debug-base (~> 0.10.4.0) + ruby-debug-base (0.10.4) + linecache (>= 0.3) + ruby-debug-base19 (0.11.24) + columnize (>= 0.3.1) + linecache19 (>= 0.5.11) + ruby_core_source (>= 0.1.4) + ruby-debug19 (0.11.6) + columnize (>= 0.3.1) + linecache19 (>= 0.5.11) + ruby-debug-base19 (>= 0.11.19) + ruby-prof (0.9.2) + ruby_core_source (0.1.4) + archive-tar-minitar (>= 0.5.2) + sqlite3 (1.3.3) + sqlite3-ruby (1.3.3) + sqlite3 (>= 1.3.3) + term-ansicolor (1.0.5) + thor (0.14.6) + treetop (1.4.9) + polyglot (>= 0.3.1) + tzinfo (0.3.25) + webrat (0.7.2) + nokogiri (>= 1.2.0) + rack (>= 1.0) + rack-test (>= 0.5.3) + +PLATFORMS + ruby + +DEPENDENCIES + ZenTest (~> 4.4.2) + arel! + aruba (= 0.2.2) + cucumber (= 0.10.0) + growl (= 1.0.3) + guard-rspec (= 0.1.9) + jruby-openssl + rack! + rails! + rake (= 0.8.7) + rb-fsevent (~> 0.3.9) + rcov (= 0.9.9) + relish (= 0.2.0) + rspec! + rspec-core! + rspec-expectations! + rspec-mocks! + rspec-rails! + ruby-debug + ruby-debug19 (~> 0.11.6) + ruby-prof (~> 0.9.2) + sqlite3-ruby + webrat (= 0.7.2) diff --git a/features/routing_specs/route_to_matcher.feature b/features/routing_specs/route_to_matcher.feature index 082ff547c6..d3374a076b 100644 --- a/features/routing_specs/route_to_matcher.feature +++ b/features/routing_specs/route_to_matcher.feature @@ -10,6 +10,21 @@ Feature: route_to matcher { :get => "/" }.should route_to(:controller => "welcome") + Scenario: passing route spec with describe title request pair + Given a file named "spec/routing/widgets_routing_spec.rb" with: + """ + require "spec_helper" + + describe "routes for Widgets" do + describe get("/widgets") do + it {should route_to "widgets#index" } + end + end + """ + + When I run "rspec spec/routing/widgets_routing_spec.rb" + Then the examples should all pass + Scenario: passing route spec with shortcut syntax Given a file named "spec/routing/widgets_routing_spec.rb" with: """ diff --git a/lib/rspec/rails/example/routing_example_group.rb b/lib/rspec/rails/example/routing_example_group.rb index e248385979..3162704bfc 100644 --- a/lib/rspec/rails/example/routing_example_group.rb +++ b/lib/rspec/rails/example/routing_example_group.rb @@ -1,4 +1,5 @@ require "action_dispatch/testing/assertions/routing" +require 'rspec/rails/example/routing_example_group/describe_with_request_pair_support' module RSpec::Rails module RoutingExampleGroup @@ -19,6 +20,8 @@ def method_missing(m, *args, &block) end included do + extend RSpec::Rails::Matchers::RoutingMatchers::RouteHelpers + extend DescribeWithRequestPairSupport metadata[:type] = :routing before do diff --git a/lib/rspec/rails/example/routing_example_group/describe_with_request_pair_support.rb b/lib/rspec/rails/example/routing_example_group/describe_with_request_pair_support.rb new file mode 100644 index 0000000000..10519609c2 --- /dev/null +++ b/lib/rspec/rails/example/routing_example_group/describe_with_request_pair_support.rb @@ -0,0 +1,21 @@ +require 'rspec/rails/example/routing_example_group/describe_with_request_pair_support/request_pair' + +module RSpec::Rails + module RoutingExampleGroup + module DescribeWithRequestPairSupport + def set_it_up(*args) + describe_title = args.first + if describe_title.is_a?(Hash) && ['get','post','put','delete'].include?(describe_title.keys.first.to_s.downcase) + describe_title.instance_eval{extend RSpec::Rails::Ruby::Hash} + describe_title.keep_first! + request_pair = RequestPair.new :http_method => describe_title.key, + :path => describe_title.value + args[0] = request_pair.to_s + superclass_metadata[:example_group].store(:describes, request_pair.to_hash) + end + super(*args) + end + end + end +end + diff --git a/lib/rspec/rails/example/routing_example_group/describe_with_request_pair_support/request_pair.rb b/lib/rspec/rails/example/routing_example_group/describe_with_request_pair_support/request_pair.rb new file mode 100644 index 0000000000..6b5304efae --- /dev/null +++ b/lib/rspec/rails/example/routing_example_group/describe_with_request_pair_support/request_pair.rb @@ -0,0 +1,21 @@ +module RSpec::Rails + module RoutingExampleGroup + module DescribeWithRequestPairSupport + class RequestPair + def initialize(args={}) + @method = args[:http_method] + @path = args[:path] + end + + def to_hash + {@method => @path} + end + + def to_s + "#{@method.to_s.upcase} #{@path}" + end + end + end + end +end + diff --git a/lib/rspec/rails/extensions.rb b/lib/rspec/rails/extensions.rb index 077a5429f7..0d4c0b8cde 100644 --- a/lib/rspec/rails/extensions.rb +++ b/lib/rspec/rails/extensions.rb @@ -1 +1,2 @@ require 'rspec/rails/extensions/active_record/base' +require 'rspec/rails/extensions/ruby/hash' diff --git a/lib/rspec/rails/extensions/ruby/.hash.rb.swo b/lib/rspec/rails/extensions/ruby/.hash.rb.swo new file mode 100644 index 0000000000000000000000000000000000000000..19bda0a51ffa4a1f7268bcbf14fda65f220cc0c3 GIT binary patch literal 12288 zcmeI&F;Ck-6bJAJBN7F{$a1s`42e@fEkdGQVPFY@p$j_OFT}z4tUDXQ(oX;jJIri+ z1wH`_I}0mfVCn|X7gI%Q=-8q8pY)IKp6|}dZ*(qf?QU+VugxWrHcfPQeY*91u16P& zs9WxvG&`>D{I%8d8k;feT*r+cD_>f}7W}Ly2Dvr+Rv+p}o2uXA!nnYe;Yna}&i0%s zZNyS>IY*6{j{?hiHN%gsPEr@7N!T9;{V^XGoVmngE-+z_qax^P*KOKx*cU+!0;48S z7M;fGBrPv}ZhiVVuV!a}7XlD~00bZa0SG_<0wXU_3%pG;WobUPKJiYgz zBb}D)`i~e`>dWsgI^dH(mq^iXaA@K(Wwjy4-(_5n+H$y_-ul~etbT2+U7e$+S5UyB AJOBUy literal 0 HcmV?d00001 diff --git a/lib/rspec/rails/extensions/ruby/.hash.rb.swp b/lib/rspec/rails/extensions/ruby/.hash.rb.swp new file mode 100644 index 0000000000000000000000000000000000000000..cbdfaf84173257a03f8a09fe4801fd8c5b32ca67 GIT binary patch literal 12288 zcmeI&yH4Cd6b9e}Z4^N80s}Nqti4=Bq7@*eK!O4x5kW!0YHXiny_mH%W24Z}&`{7p z%^T421bK{-6Y2l1*1QLWE_8;kAdyeO_{>t46n!6jD>Weo|(#D9^E-p52RFA%W zBI*_gY104Up1j%WagB|Lb*7`n-r`d8wF#&7KtD6-fzd}g)Tz7gah_V=6v2s~X54Sv zv@jt{#bz8fB0lyFXKqB(uMPnSKmY;|fB*y_0D-|2$g?53mscN_j7x^<$OR1o5P$##AOHaf zKmY;|fB*y_0D%u8pd+I55u)D`_y5294d8B+=$GWDOFRil z{>d7DC4U~*`yfVm4G2I00uX=z1Rwwb2tWV=5O^N~+>c19>htOP{7xy$Nyn38=7|n@ zCeyL;Iy1|@prYXS}k`Y^`kT@5>{K~;drWh+u!9_eXF(Y&e78Y DPfeSi literal 0 HcmV?d00001 diff --git a/lib/rspec/rails/extensions/ruby/hash.rb b/lib/rspec/rails/extensions/ruby/hash.rb new file mode 100644 index 0000000000..b12bbff8df --- /dev/null +++ b/lib/rspec/rails/extensions/ruby/hash.rb @@ -0,0 +1,18 @@ +module RSpec::Rails + module Ruby + module Hash + def key + self.keys.first + end + + def value + self.values.first + end + + def keep_first! + pair = self.first + self.replace(pair.first => pair.last) + end + end + end +end diff --git a/spec/rspec/rails/example/routing_example_group/describe_with_request_pair_support/request_pair_spec.rb b/spec/rspec/rails/example/routing_example_group/describe_with_request_pair_support/request_pair_spec.rb new file mode 100644 index 0000000000..72d9c3ce35 --- /dev/null +++ b/spec/rspec/rails/example/routing_example_group/describe_with_request_pair_support/request_pair_spec.rb @@ -0,0 +1,20 @@ +require 'spec_helper' + +module RSpec::Rails::RoutingExampleGroup + module DescribeWithRequestPairSupport + describe RequestPair do + before :each do + @request_pair = RequestPair.new :http_method => :get, + :path => "/" + end + + it 'should became a hash' do + @request_pair.to_hash.should be == {:get => "/"} + end + + it 'should became a string' do + @request_pair.to_s.should be == "GET /" + end + end + end +end diff --git a/spec/rspec/rails/example/routing_example_group_spec.rb b/spec/rspec/rails/example/routing_example_group_spec.rb index 4c3ed0c543..fd805f9627 100644 --- a/spec/rspec/rails/example/routing_example_group_spec.rb +++ b/spec/rspec/rails/example/routing_example_group_spec.rb @@ -28,5 +28,25 @@ module RSpec::Rails example.foo_path.should == "foo" end end + + context "use route helpers" do + it "should get 'path' return {:get => 'path'}" do + group = RSpec::Core::ExampleGroup.describe do + include RoutingExampleGroup + end + group.get("path").should be == {:get => "path"} + end + end + + context "use request pair in describe title" do + it "should request pair be the subject" do + group = RSpec::Core::ExampleGroup.describe do + include RoutingExampleGroup + end + inner_group = group.describe ({:get => "path"}) + inner_group.new.subject.should be == {:get => "path"} + end + end + end end diff --git a/spec/rspec/rails/extensions/ruby/hash_spec.rb b/spec/rspec/rails/extensions/ruby/hash_spec.rb new file mode 100644 index 0000000000..f902c553c8 --- /dev/null +++ b/spec/rspec/rails/extensions/ruby/hash_spec.rb @@ -0,0 +1,23 @@ +require 'spec_helper' + +module RSpec::Rails::Ruby + describe "Hash" do + before :each do + @hash = {:name => "nobody", :age => 0} + @hash.instance_eval{extend Hash} + end + + it 'should return the first element' do + @hash.keep_first! + @hash.should be == {:name => "nobody"} + end + + it 'should return the key of the first element' do + @hash.key.should be == :name + end + + it 'should return the value of the first element' do + @hash.value.should be == "nobody" + end + end +end