capybara-json 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +4 -0
- data/README.md +22 -19
- data/VERSION +1 -1
- data/capybara-json.gemspec +1 -1
- data/lib/capybara/httpclient_json/driver.rb +4 -0
- data/lib/capybara/json.rb +1 -1
- data/lib/capybara/rack_test_json/driver.rb +4 -0
- data/spec/capybara/httpclient_json/driver_spec.rb +12 -12
- data/spec/capybara/rack_test_json/driver_spec.rb +12 -12
- data/spec/spec_helper.rb +4 -2
- data/spec/support/driver_examples.rb +21 -4
- metadata +5 -4
    
        data/CHANGELOG.md
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | @@ -9,22 +9,25 @@ capybara-json provides the same interface to testing JSON API (both local and re | |
| 9 9 | 
             
            Capybara is an acceptance test framework, and it has no interest with client error(4xx response).
         | 
| 10 10 |  | 
| 11 11 | 
             
            ## USAGE
         | 
| 12 | 
            -
             | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
| 16 | 
            -
             | 
| 17 | 
            -
             | 
| 18 | 
            -
             | 
| 19 | 
            -
             | 
| 20 | 
            -
             | 
| 21 | 
            -
             | 
| 22 | 
            -
             | 
| 23 | 
            -
             | 
| 24 | 
            -
             | 
| 25 | 
            -
             | 
| 26 | 
            -
             | 
| 27 | 
            -
             | 
| 28 | 
            -
             | 
| 29 | 
            -
             | 
| 30 | 
            -
             | 
| 12 | 
            +
             | 
| 13 | 
            +
            ```ruby
         | 
| 14 | 
            +
            require 'capybara/json'
         | 
| 15 | 
            +
            include Capybara::Json
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            Capybara.current_driver = :rack_test_json
         | 
| 18 | 
            +
            post '/', { "this is" => "json" } # POST '/'
         | 
| 19 | 
            +
            json   #=> parsed json response
         | 
| 20 | 
            +
            source #=> raw response body
         | 
| 21 | 
            +
            get  '/errors/400'
         | 
| 22 | 
            +
            status_code #=> 400
         | 
| 23 | 
            +
            get! '/errors' #=> raise Capybara::Json::Error
         | 
| 24 | 
            +
             | 
| 25 | 
            +
            Capybara.current_driver = :httpclient_json
         | 
| 26 | 
            +
            Capybara.app_host = 'http://example.com'
         | 
| 27 | 
            +
            post '/', { "this is" => "json" } # POST 'http://example.com/'
         | 
| 28 | 
            +
            json   #=> parsed json response
         | 
| 29 | 
            +
            source #=> raw response body
         | 
| 30 | 
            +
            get  '/errors/400'
         | 
| 31 | 
            +
            status_code #=> 400
         | 
| 32 | 
            +
            get! '/errors' #=> raise Capybara::Json::Error
         | 
| 33 | 
            +
            ```
         | 
    
        data/VERSION
    CHANGED
    
    | @@ -1 +1 @@ | |
| 1 | 
            -
            0.2. | 
| 1 | 
            +
            0.2.3
         | 
    
        data/capybara-json.gemspec
    CHANGED
    
    | @@ -21,7 +21,7 @@ Gem::Specification.new do |s| | |
| 21 21 |  | 
| 22 22 | 
             
              # for testing
         | 
| 23 23 | 
             
              s.add_development_dependency "rake"
         | 
| 24 | 
            -
              s.add_development_dependency "rspec", "~> 2. | 
| 24 | 
            +
              s.add_development_dependency "rspec", "~> 2.11"
         | 
| 25 25 | 
             
              s.add_development_dependency "sinatra"
         | 
| 26 26 | 
             
              s.add_development_dependency "thin"
         | 
| 27 27 | 
             
              s.add_development_dependency "yajl-ruby"
         | 
    
        data/lib/capybara/json.rb
    CHANGED
    
    
| @@ -5,23 +5,23 @@ klass = Capybara::HTTPClientJson::Driver | |
| 5 5 | 
             
            describe klass do
         | 
| 6 6 | 
             
              before { @driver = described_class.new(JsonTestApp) }
         | 
| 7 7 |  | 
| 8 | 
            -
               | 
| 9 | 
            -
               | 
| 10 | 
            -
               | 
| 11 | 
            -
               | 
| 12 | 
            -
               | 
| 13 | 
            -
               | 
| 14 | 
            -
               | 
| 8 | 
            +
              it_behaves_like 'driver'
         | 
| 9 | 
            +
              it_behaves_like 'driver with header support'
         | 
| 10 | 
            +
              it_behaves_like 'driver with custom header support'
         | 
| 11 | 
            +
              it_behaves_like 'driver with status code support'
         | 
| 12 | 
            +
              it_behaves_like 'driver with cookies support'
         | 
| 13 | 
            +
              it_behaves_like "driver with redirect support"
         | 
| 14 | 
            +
              it_behaves_like 'driver with infinite redirect detection'
         | 
| 15 15 |  | 
| 16 | 
            -
               | 
| 17 | 
            -
               | 
| 16 | 
            +
              it_behaves_like 'driver to post json'
         | 
| 17 | 
            +
              it_behaves_like 'driver to put json'
         | 
| 18 18 |  | 
| 19 | 
            -
               | 
| 20 | 
            -
               | 
| 19 | 
            +
              it_behaves_like 'driver for client error'
         | 
| 20 | 
            +
              it_behaves_like 'driver for server error'
         | 
| 21 21 | 
             
            end
         | 
| 22 22 |  | 
| 23 23 | 
             
            describe klass do
         | 
| 24 24 | 
             
              before { @driver = described_class.new(JsonTestApp, :follow_redirect => false) }
         | 
| 25 25 |  | 
| 26 | 
            -
               | 
| 26 | 
            +
              it_behaves_like "driver not to follow redirect"
         | 
| 27 27 | 
             
            end
         | 
| @@ -5,23 +5,23 @@ klass = Capybara::RackTestJson::Driver | |
| 5 5 | 
             
            describe klass do
         | 
| 6 6 | 
             
              before { @driver = described_class.new(JsonTestApp) }
         | 
| 7 7 |  | 
| 8 | 
            -
               | 
| 9 | 
            -
               | 
| 10 | 
            -
               | 
| 11 | 
            -
               | 
| 12 | 
            -
               | 
| 13 | 
            -
               | 
| 14 | 
            -
               | 
| 8 | 
            +
              it_behaves_like 'driver'
         | 
| 9 | 
            +
              it_behaves_like 'driver with header support'
         | 
| 10 | 
            +
              it_behaves_like 'driver with custom header support'
         | 
| 11 | 
            +
              it_behaves_like 'driver with status code support'
         | 
| 12 | 
            +
              it_behaves_like 'driver with cookies support'
         | 
| 13 | 
            +
              it_behaves_like "driver with redirect support"
         | 
| 14 | 
            +
              it_behaves_like 'driver with infinite redirect detection'
         | 
| 15 15 |  | 
| 16 | 
            -
               | 
| 17 | 
            -
               | 
| 16 | 
            +
              it_behaves_like 'driver to post json'
         | 
| 17 | 
            +
              it_behaves_like 'driver to put json'
         | 
| 18 18 |  | 
| 19 | 
            -
               | 
| 20 | 
            -
               | 
| 19 | 
            +
              it_behaves_like 'driver for client error'
         | 
| 20 | 
            +
              it_behaves_like 'driver for server error'
         | 
| 21 21 | 
             
            end
         | 
| 22 22 |  | 
| 23 23 | 
             
            describe klass do
         | 
| 24 24 | 
             
              before { @driver = described_class.new(JsonTestApp, :follow_redirect => false) }
         | 
| 25 25 |  | 
| 26 | 
            -
               | 
| 26 | 
            +
              it_behaves_like "driver not to follow redirect"
         | 
| 27 27 | 
             
            end
         | 
    
        data/spec/spec_helper.rb
    CHANGED
    
    | @@ -1,7 +1,9 @@ | |
| 1 | 
            -
             | 
| 2 | 
            -
            $: << File.expand_path('../lib', ROOT)
         | 
| 1 | 
            +
            require "bundler/setup"
         | 
| 3 2 |  | 
| 4 3 | 
             
            require "pry"
         | 
| 4 | 
            +
            require "tapp"
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            ROOT = File.dirname(__FILE__)
         | 
| 5 7 |  | 
| 6 8 | 
             
            require 'capybara/json'
         | 
| 7 9 | 
             
            Dir[File.expand_path("support/**/*.rb", ROOT)].each {|f| require f }
         | 
| @@ -25,11 +25,28 @@ shared_examples_for 'driver' do | |
| 25 25 | 
             
              describe '#body' do
         | 
| 26 26 | 
             
                it "should return json reponses" do
         | 
| 27 27 | 
             
                  @driver.visit('/')
         | 
| 28 | 
            +
                  @driver.body.should be_a(Hash)
         | 
| 28 29 | 
             
                  @driver.body.should include('Hello world!')
         | 
| 29 30 | 
             
                end
         | 
| 30 31 | 
             
                # pending encoding
         | 
| 31 32 | 
             
              end
         | 
| 32 33 |  | 
| 34 | 
            +
              context '#source' do
         | 
| 35 | 
            +
                it "should return raw reponse" do
         | 
| 36 | 
            +
                  @driver.visit('/')
         | 
| 37 | 
            +
                  @driver.source.should be_a(String)
         | 
| 38 | 
            +
                  @driver.source.should include('Hello world!')
         | 
| 39 | 
            +
                end
         | 
| 40 | 
            +
              end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
              describe '#json' do
         | 
| 43 | 
            +
                it "should return json reponses" do
         | 
| 44 | 
            +
                  @driver.visit('/')
         | 
| 45 | 
            +
                  @driver.json.should be_a(Hash)
         | 
| 46 | 
            +
                  @driver.json.should include('Hello world!')
         | 
| 47 | 
            +
                end
         | 
| 48 | 
            +
                # pending encoding
         | 
| 49 | 
            +
              end
         | 
| 33 50 | 
             
              # TODO: find by jsonpath?
         | 
| 34 51 | 
             
            end
         | 
| 35 52 |  | 
| @@ -92,7 +109,7 @@ end | |
| 92 109 |  | 
| 93 110 | 
             
            shared_examples_for 'driver for client error' do
         | 
| 94 111 | 
             
              it 'should not raise exception' do
         | 
| 95 | 
            -
                expect { @driver.get('/errors/400') }. | 
| 112 | 
            +
                expect { @driver.get('/errors/400') }.not_to raise_exception
         | 
| 96 113 | 
             
              end
         | 
| 97 114 |  | 
| 98 115 | 
             
              it 'should make the status code available' do
         | 
| @@ -111,13 +128,13 @@ shared_examples_for 'driver for client error' do | |
| 111 128 | 
             
              end
         | 
| 112 129 |  | 
| 113 130 | 
             
              it 'should raise error using bang!' do
         | 
| 114 | 
            -
                expect { @driver.get!('/errors/400') }. | 
| 131 | 
            +
                expect { @driver.get!('/errors/400') }.to raise_exception(Capybara::Json::Error)
         | 
| 115 132 | 
             
              end
         | 
| 116 133 | 
             
            end
         | 
| 117 134 |  | 
| 118 135 | 
             
            shared_examples_for 'driver for server error' do
         | 
| 119 136 | 
             
              it 'should not raise exception' do
         | 
| 120 | 
            -
                expect { @driver.get('/errors/500') }. | 
| 137 | 
            +
                expect { @driver.get('/errors/500') }.not_to raise_exception
         | 
| 121 138 | 
             
              end
         | 
| 122 139 |  | 
| 123 140 | 
             
              it 'should make the status_code available' do
         | 
| @@ -126,6 +143,6 @@ shared_examples_for 'driver for server error' do | |
| 126 143 | 
             
              end
         | 
| 127 144 |  | 
| 128 145 | 
             
              it 'should raise error using bang!' do
         | 
| 129 | 
            -
                expect { @driver.get!('/errors/500') }. | 
| 146 | 
            +
                expect { @driver.get!('/errors/500') }.to raise_exception(Capybara::Json::Error)
         | 
| 130 147 | 
             
              end
         | 
| 131 148 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: capybara-json
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.2. | 
| 4 | 
            +
              version: 0.2.3
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 7 | 
             
            authors:
         | 
| @@ -9,7 +9,7 @@ authors: | |
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2012- | 
| 12 | 
            +
            date: 2012-08-15 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: capybara
         | 
| @@ -82,7 +82,7 @@ dependencies: | |
| 82 82 | 
             
                requirements:
         | 
| 83 83 | 
             
                - - ~>
         | 
| 84 84 | 
             
                  - !ruby/object:Gem::Version
         | 
| 85 | 
            -
                    version: '2. | 
| 85 | 
            +
                    version: '2.11'
         | 
| 86 86 | 
             
              type: :development
         | 
| 87 87 | 
             
              prerelease: false
         | 
| 88 88 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| @@ -90,7 +90,7 @@ dependencies: | |
| 90 90 | 
             
                requirements:
         | 
| 91 91 | 
             
                - - ~>
         | 
| 92 92 | 
             
                  - !ruby/object:Gem::Version
         | 
| 93 | 
            -
                    version: '2. | 
| 93 | 
            +
                    version: '2.11'
         | 
| 94 94 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 95 95 | 
             
              name: sinatra
         | 
| 96 96 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -253,3 +253,4 @@ test_files: | |
| 253 253 | 
             
            - spec/spec_helper.rb
         | 
| 254 254 | 
             
            - spec/support/driver_examples.rb
         | 
| 255 255 | 
             
            - spec/support/json_test_app.rb
         | 
| 256 | 
            +
            has_rdoc: 
         |