require_relative 'spec_helper' describe 'app' do include Rack::Test::Methods it 'should echo string when request with echostr parameter' do get '/weixin?echostr=test' last_response.body.should include 'test' end it 'should return user defined text message when receive a text request message' do WeiBackend::MessageDispatcher.on_text do 'hello world' end post '/weixin', TEXT_MESSAGE_REQUEST, 'CONTENT_TYPE' => 'text/xml' last_response.body.should include '' last_response.body.should include '' end it 'should return user defined news message when receive a text request message' do WeiBackend::MessageDispatcher.on_text do {:title => 'title', :description => 'desc', :picture_url => 'pic url', :url => 'url'} end post '/weixin', TEXT_MESSAGE_REQUEST, 'CONTENT_TYPE' => 'text/xml' last_response.body.should include '' last_response.body.should include '<![CDATA[title]]>' end it 'should return news message when receive a text request message and user defined a multi-news' do WeiBackend::MessageDispatcher.on_text do [{ :title => 'title', :description => 'desc', :picture_url => 'pic url', :url => 'url' }, { :title => 'title1', :description => 'desc1', :picture_url => 'pic url1', :url => 'url1' }] end post '/weixin', TEXT_MESSAGE_REQUEST, 'CONTENT_TYPE' => 'text/xml' last_response.body.should include '' last_response.body.should include '<![CDATA[title]]>' last_response.body.should include '<![CDATA[title1]]>' end it 'should echo location message when receive a location event message' do WeiBackend::MessageDispatcher.on_location do "location event: #{params[:Latitude]}" end post '/weixin', LOCATION_EVENT_REQUEST, 'CONTENT_TYPE' => 'text/xml' last_response.body.should include '' last_response.body.should include '' end it 'should echo location message when receive a location event message' do WeiBackend::MessageDispatcher.on_subscribe do 'Thank you for subscribe!' end post '/weixin', SUBSCRIBE_EVENT_REQUEST, 'CONTENT_TYPE' => 'text/xml' last_response.body.should include '' last_response.body.should include '' end it 'should do something when user have set token' do WeiBackend::MessageDispatcher.on_subscribe do 'Thank you for subscribe!' end WeiBackend::MessageDispatcher.token 'combustest' post '/weixin?signature=0d144fa22f4119dbb2f6fe9710f3b732fb45092b×tamp=1388674716&nonce=1388564676', SUBSCRIBE_EVENT_REQUEST, 'CONTENT_TYPE' => 'text/xml' last_response.body.should include '' last_response.body.should include '' end end