GithubHelp home page GithubHelp logo

capybara-json's Introduction

capybara-json Build Status Dependency Status

testing ruby: 1.9.3, 2.0.0, 2.1.x, 2.2.x; Capybara: 0.4.x, 1.1.x, 2.0.x

About capybara-json

capybara-json provides the same interface to testing JSON API (both local and remote)

Capybara is an acceptance test framework, and it has no interest with client error(4xx response).

USAGE

require 'capybara/json'
include Capybara::Json

Capybara.current_driver = :rack_test_json
Capybara.app = MyRackApp
post '/', { "this is" => "json" } # POST '/'
json     #=> parsed json response
raw_json #=> raw response body

get  '/errors/400'
status_code #=> 400
get! '/errors' #=> raise Capybara::Json::Error

get  '/errors', {}, { 'header' => '' } # set request headers
response_headers #=> get response headers

Capybara.current_driver = :httpclient_json
Capybara.app_host = 'http://example.com'
post '/', { "this is" => "json" } # POST 'http://example.com/'
json     #=> parsed json response
raw_json #=> raw response body

get  '/errors/400'
status_code #=> 400
get! '/errors' #=> raise Capybara::Json::Error

get  '/errors', {}, { 'header' => '' } # set request headers
response_headers #=> get response headers

capybara-json's People

Contributors

gkellogg avatar hanachin avatar medlefsen avatar okitan avatar sonots avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

capybara-json's Issues

NameError Exception: undefined local variable or method `json'

I get the above error when I use capybara-json as README says:

require 'capybara/json'
include Capybara::Json

Capybara.current_driver = :rack_test_json
post '/', { "this is" => "json" } # POST '/'
json   #=> NameError Exception: undefined local variable or method `json' 

This should be because Capybara::Session::DSL_METHODS https://github.com/jnicklas/capybara/blob/master/lib/capybara/session.rb#L45 does not include json methods, thus json DSL is not created.

Basically, this bug is caused because test cases for mix-in usage are completely lacked. Test cases using driver directly is not enough.


I also think that it would be nice to run the mix-in usage test cases with various versions of capybara because capybara people sometimes changes driver interfaces, etc and affects capybara-json. It would also be nice to write explicitly down that capybara-json supports what versions of capybara if possible. For this purpose, bundler-auto-update would be useful.

Well this is sort of awkward

So this is kind of my Jon Stewart on Crossfire moment. I don't mean to offend you, but I feel that the premise of this gem is fundamentally flawed. You're basically (badly) replicating the functionality of RackTest, by going through a private undocumented Capybara API. Not only is this going to break in the future, but there's also not really a point to doing this, when you could just use RackTest directly.

I've seen people make this mistake a lot, so you're definitely not alone in this. I've blogged about it here: http://elabs.se/blog/34-capybara-and-testing-apis

Again, I really hope you don't take this personally. And I apologize for voicing this in a public forum, but there doesn't seem to be an email address on your GitHub profile.

(I previously sent this from my employer's GitHub account by accident, I want to stress that this is my opinion, and not my employer's)

undefined method `html' for #<Capybara::RackTestJson::Driver:0x007feb6a44c778> with Capybara2.0.2

When I call #source or #body method, this error appears.

It seems that no driver have #source or #body method anymore on Capyabara 2.0.1+. See teamcapybara/capybara@ae7c564. They are now just alias to #html method in lib/capybara/session.rb, so a driver can have only #html method effectively now. And the error on the title appears when we call #source or #body without #html method defined.

FYI: I have not read carefully yet, but it seems that the change is basically coming from this issue teamcapybara/capybara#871. It seems that hey decided to integrate #source and #body to one #html anyway.

Add support for Capybara::Session

When I run

@session = Capybara::Session.new(:rack_test_json)
@session.post('/some/path', {some: 'data'})

It just gives me NoMethodError: undefined method 'post' for #<Capybara::Session>. The same for other HTTP verbs and .json and .raw_json.

When I design an web api for some sort of workflow, it's essential to write tests for cooperation among people who don't share sessions. Please think of adding support for Capybara::Session or implement something similar.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.