diff --git a/Gemfile.lock b/Gemfile.lock index 7655d50e..a00e61da 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -72,7 +72,6 @@ GEM thor (~> 0.14.0) rake (0.8.7) rcov (0.9.8) - responders_backport (0.1.2) rspec (2.0.0.beta.19) rspec-core (= 2.0.0.beta.19) rspec-expectations (= 2.0.0.beta.19) @@ -118,7 +117,6 @@ DEPENDENCIES rack-conneg rails (>= 3.0.0) rcov - responders_backport rspec-rails (>= 2.0.0.beta.19) ruby-debug sinatra diff --git a/Rakefile b/Rakefile index 1db62f6f..e40ae544 100644 --- a/Rakefile +++ b/Rakefile @@ -104,19 +104,11 @@ namespace :test do task :all => ["spec","integration"] - # namespace :rcov do - # Spec::Rake::SpecTask.new('rcov') do |t| - # t.spec_opts = %w(-fs --color) - # t.spec_files = FileList['spec/units/**/*_spec.rb'] - # t.rcov = true - # t.rcov_opts = ["-e", "/Library*", "-e", "~/.rvm", "-e", "spec", "-i", "bin"] - # end - # desc 'Run coverage test with fake server' - # task :run do - # start_server_and_invoke_test('test:rcov:rcov') - # end - # end - +end + +RSpec::Core::RakeTask.new(:spec) do |t| + # t.spec_files = FileList['spec_*.rb'] + # t.options = '-v' end Rake::GemPackageTask.new(spec) do |pkg| diff --git a/lib/restfulie.rb b/lib/restfulie.rb index 6403e5f0..eb90ab73 100644 --- a/lib/restfulie.rb +++ b/lib/restfulie.rb @@ -5,6 +5,18 @@ require 'restfulie/client' require 'restfulie/server' +class RestfulieDslBuilder + def initialize + @traits = [Restfulie::Client::Feature::Nil.new] + end + def method_missing(sym, *args) + trait = "Restfulie::Client::Feature::#{sym.to_s.classify}".constantize + @traits << trait + self.extend trait + self + end +end + # Shortcut to Restfulie::Client::EntryPoint module Restfulie @@ -22,6 +34,10 @@ def self.using(&block) RestfulieUsing.new.instance_eval(&block) end + def self.use(&block) + RestfulieDslBuilder.new.instance_eval(&block) + end + end class RestfulieUsing diff --git a/lib/restfulie/client.rb b/lib/restfulie/client.rb index 77fb43d8..35ddbbf8 100644 --- a/lib/restfulie/client.rb +++ b/lib/restfulie/client.rb @@ -10,6 +10,7 @@ module Client autoload :Base, 'restfulie/client/base' autoload :Mikyung, 'restfulie/client/mikyung' autoload :Cache, 'restfulie/client/cache' + autoload :Feature, 'restfulie/client/feature' mattr_accessor :cache_provider, :cache_store diff --git a/lib/restfulie/client/feature.rb b/lib/restfulie/client/feature.rb new file mode 100644 index 00000000..7a5a7937 --- /dev/null +++ b/lib/restfulie/client/feature.rb @@ -0,0 +1,6 @@ +module Restfulie::Client + module Feature + class Nil + end + end +end \ No newline at end of file diff --git a/lib/restfulie/client/http/request_adapter.rb b/lib/restfulie/client/http/request_adapter.rb index 0241cdc9..a8682e47 100644 --- a/lib/restfulie/client/http/request_adapter.rb +++ b/lib/restfulie/client/http/request_adapter.rb @@ -76,15 +76,6 @@ def headers @headers ||= {} end - # Executes a request against your server and return a response instance without {Error} - # * method: :get,:post,:delete,:head,:put - # * path: '/posts' - # * args: payload: 'some text' and/or headers: {'Accept' => '*/*', 'Content-Type' => 'application/atom+xml'} - def request(method = nil, path = nil, *args) - @response_handler = Restfulie::Client::Response::IgnoreError.new(@response_handler) - request!(method, path, *args) - end - # Executes a request against your server and return a response instance. # * method: :get,:post,:delete,:head,:put # * path: '/posts' @@ -113,6 +104,16 @@ def request!(method, path, *args) end + + # Executes a request against your server and return a response instance without {Error} + # * method: :get,:post,:delete,:head,:put + # * path: '/posts' + # * args: payload: 'some text' and/or headers: {'Accept' => '*/*', 'Content-Type' => 'application/atom+xml'} + def request(method = nil, path = nil, *args) + @response_handler = Restfulie::Client::Response::IgnoreError.new(@response_handler) + request!(method, path, *args) + end + private def get_connection_provider diff --git a/lib/restfulie/client/http/request_history.rb b/lib/restfulie/client/http/request_history.rb index 48757f46..fd8c260f 100644 --- a/lib/restfulie/client/http/request_history.rb +++ b/lib/restfulie/client/http/request_history.rb @@ -39,6 +39,14 @@ def request!(method=nil, path=nil, *args)#:nodoc: end end + def request(method = nil, path = nil, *args) + begin + request!(method, path, *args) + rescue Restfulie::Client::HTTP::Error::RESTError => se + se + end + end + def history(number) @snapshot = snapshots[number] raise "Undefined snapshot for #{number}" unless @snapshot diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 00000000..c2f75aff --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,8 @@ +# require File.expand_path("../../config/environment", __FILE__) +require 'rspec' + +# Requires supporting files with custom matchers and macros, etc, +# in ./support/ and its subdirectories. +Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f} + +require 'restfulie' \ No newline at end of file diff --git a/spec/unit/restfulie_spec.rb b/spec/unit/restfulie_spec.rb new file mode 100644 index 00000000..3146047e --- /dev/null +++ b/spec/unit/restfulie_spec.rb @@ -0,0 +1,22 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +context Restfulie do + + context "when building restfulie" do + + it "should create a restfulie with an at method" do + Restfulie.respond_to?(:at).should be_true + end + + module Restfulie::Client::Feature::Custom + def custom_history + end + end + + it "should allow adding extra methods by usage" do + Restfulie.use{custom}.respond_to?(:custom_history).should be_true + end + + end + +end diff --git a/tests/spec/requests/http/adapter_spec.rb b/tests/spec/requests/http/adapter_spec.rb index 36246ff6..897cc107 100644 --- a/tests/spec/requests/http/adapter_spec.rb +++ b/tests/spec/requests/http/adapter_spec.rb @@ -164,6 +164,10 @@ before(:all) do @host = "http://localhost:4567" @builder = ::Restfulie::Client::HTTP::RequestHistoryExecutor.new(@host) + @builder = Restfulie.using { + request_history + verb_request + }.at(@host) end it "should remember last requests" do