spec/gon/gon_spec.rb in gon-2.0.4 vs spec/gon/gon_spec.rb in gon-2.0.5

- old
+ new

@@ -1,10 +1,11 @@ # gon_spec_rb require 'gon' describe Gon, '#all_variables' do - before(:each) do + + before(:each) do Gon.request_env = {} end it 'returns all variables in hash' do Gon.a = 1 @@ -47,18 +48,47 @@ controller.instance_variable_set('@objects', objects) Gon.rabl 'spec/test_data/sample.rabl', :controller => controller Gon.objects.length.should == 2 end - it 'render json from jbuilder template' do - Gon.clear - controller = ActionController::Base.new - objects = [1,2] - controller.instance_variable_set('@objects', objects) - Gon.jbuilder 'spec/test_data/sample.json.jbuilder', :controller => controller - Gon.objects.length.should == 2 + if RUBY_VERSION =~ /1.9/ + require 'jbuilder' + require 'gon/jbuilder' + + it 'render json from jbuilder template' do + Gon.clear + controller = ActionController::Base.new + objects = [1,2] + controller.instance_variable_set('@objects', objects) + Gon.jbuilder 'spec/test_data/sample.json.jbuilder', :controller => controller + Gon.objects.length.should == 2 + end + + it 'render json from jbuilder template with a partial' do + Gon.clear + controller = ActionController::Base.new + controller.view_paths << 'spec/test_data' + objects = [1,2] + controller.instance_variable_set('@objects', objects) + Gon.jbuilder 'spec/test_data/sample_with_partial.json.jbuilder', :controller => controller + Gon.objects.length.should == 2 + end + + it 'should throw error if you use gon.jbuilder with ruby < 1.9+' do + RUBY_VERSION = '1.8.7' + + expect { Gon.jbuilder 'some_path' }.to raise_error(NoMethodError, /1.9/) + end + + it 'should raise error if you use gon.jbuilder without requairing jbuilder gem' do + RUBY_VERSION = '1.9.2' + Gon.send(:remove_const, :Jbuilder) + + expect { Gon.jbuilder 'some_path' }.to raise_error(NoMethodError, /Gemfile/) + end end def request @request ||= double 'request', :env => {} end + end