Last active
August 29, 2015 14:11
-
-
Save celsoMartins/9b9935c07eaaa334d346 to your computer and use it in GitHub Desktop.
NoMethodError: undefined method `join' for #<String:0x007f62c3e6fb90>
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Stacktrace: | |
26) UserAPI /post user with no parameters with no json | |
Failure/Error: before { post '/user' } | |
NoMethodError: | |
undefined method `join' for #<String:0x007f62c3e6fb90> | |
# ./spec/routes/user_api_spec.rb:7:in `block (5 levels) in <top (required)>' | |
Gemfile: | |
source 'http://rubygems.org' | |
ruby '2.1.3' | |
gem 'sinatra', '1.4.5', :require => 'sinatra/base' | |
gem 'tilt', '1.3.4' | |
gem 'mongoid' | |
gem 'bson_ext' | |
gem 'temple', '0.4.1' | |
gem 'slim', '1.3.0' | |
gem 'rspec' | |
gem 'rack-test' | |
gem 'simplecov' | |
gem 'database_cleaner' | |
gem 'json_spec' | |
gem 'thin' | |
gem 'json' | |
The user_spec_api.rb | |
describe 'UserAPI' do | |
include Rack::Test::Methods | |
describe '/post user' do | |
context 'with no parameters' do | |
context 'with no json' do | |
before { post '/user' } | |
it { expect(last_response.status).to be 500 } | |
it { expect(last_response.errors).to include('ArgumentError') } | |
it { expect(last_response.errors).to include('We need an email to process your request.') } | |
end | |
end | |
context 'with a valid email' do | |
before { post '/user?email=foo@bar.com' } | |
it { expect(last_response.status).to be 200 } | |
it { expect(User.count).to be 1} | |
it { expect(User.last.email).to eq 'foo@bar.com'} | |
end | |
end | |
end | |
The user_api.rb | |
module Sinatra | |
module EasyBar | |
module UserAPI | |
def self.registered(app) | |
app.post '/user' do | |
raise(ArgumentError, 'We need an email to process your request.') if params['email'].blank? | |
User.create! email: params['email'] | |
end | |
end | |
end | |
end | |
end |
A more structured discussion
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The answer
sinatra/sinatra@b39d72d