Hi,
Here is my route :-
post '/export' do
gist = List.new(Task.all).to_gist
redirect gist['html_url']
end
and the spec :-
describe "/export" do
let(:gist) { double('Gist') }
let(:url) { "
http://example.org/gist" }
it 'exports as a gist' do
allow_any_instance_of(List).to receive(:to_gist) { gist }
allow(gist).to receive(:[]).with('html_url').and_return(url)
post "/export"
expect(last_response).to be_redirect
follow_redirect!
expect(last_request.url).to eq(url)
end
end
Now, when I am running my test :
[arup@to_do_app]$ rspec spec/todo_spec.rb:42
Run options: include {:locations=>{"./spec/todo_spec.rb"=>[42]}}
task is
F
Failures:
1) ToDo App routes /export exports as a gist
Failure/Error: follow_redirect!
NoMethodError:
undefined method `id' for nil:NilClass
# ./views/show.erb:1:in `block in singleton class'
# ./views/show.erb:131067:in `instance_eval'
# ./views/show.erb:131067:in `singleton class'
# ./views/show.erb:131065:in `__tilt_80054700'
#
/home/arup/.rvm/gems/ruby-2.1.4@2_1_4/gems/tilt-1.4.1/lib/tilt/template.rb:170:in
`call'
#
/home/arup/.rvm/gems/ruby-2.1.4@2_1_4/gems/tilt-1.4.1/lib/tilt/template.rb:170:in
`evaluate'
#
/home/arup/.rvm/gems/ruby-2.1.4@2_1_4/gems/tilt-1.4.1/lib/tilt/template.rb:103:in
`render'
#
/home/arup/.rvm/gems/ruby-2.1.4@2_1_4/gems/sinatra-1.4.5/lib/sinatra/base.rb:814:in
`render'
#
/home/arup/.rvm/gems/ruby-2.1.4@2_1_4/gems/sinatra-1.4.5/lib/sinatra/base.rb:665:in
`erb'
# ./todo.rb:41:in `block in <class:ToDoApp>'
#
/home/arup/.rvm/gems/ruby-2.1.4@2_1_4/gems/sinatra-1.4.5/lib/sinatra/base.rb:1603:in
`call'
Why it is not working? As per this Q/A -
http://stackoverflow.com/questions/7424443/how-do-i-test-a-redirect-in-sinatra-using-rspec it should work.
Any pointer please ?
--
================
Regards,
Arup Rakshit
================
Debugging is twice as hard as writing the code in the first place. Therefore,
if you write the code as cleverly as possible, you are, by definition, not
smart enough to debug it.
--Brian Kernighan