spec/lib/dependencies_spec.rb in mango-0.5.3 vs spec/lib/dependencies_spec.rb in mango-0.5.4

- old
+ new

@@ -8,26 +8,14 @@ describe "class constant and variable defaults" do it "supports ruby 1.9.2" do Mango::Dependencies::SUPPORTED_RUBY_VERSIONS.should == ["1.9.2"] end - it "development gem names and versions should be correct" do - expected = { - :"rack-test" => "0.5.6", - :rspec => "2.0.1", - :yard => "0.6.1", - :"yard-sinatra" => "0.5.1", - :bluecloth => "2.0.9" - } - - Mango::Dependencies::DEVELOPMENT_GEMS.should == expected - end - it "file name to gem name look-up table should be correct" do expected = { :"rack/test" => :"rack-test", - :"rspec/core/rake_task" => :rspec, + :"rspec/core/rake_task" => :"rspec-core", :"yard/sinatra" => :"yard-sinatra" } Mango::Dependencies::FILE_NAME_TO_GEM_NAME.should == expected end @@ -36,11 +24,11 @@ end end ################################################################################################# - describe ".check_ruby_version (private)" do + describe ".check_ruby_version" do before(:each) do $stderr = StringIO.new end after(:each) do @@ -48,132 +36,107 @@ end def expected_message(version) @expected_message = <<-ERROR This library supports Ruby 1.9.2, but you're using #{version}. -Please visit http://www.ruby-lang.org/ or http://rvm.beginrescueend.com/ for installation instructions. +I recommend using Ruby Version Manager to install, manage and work with multiple Ruby environments. +http://rvm.beginrescueend.com/ ERROR end it "aborts for ruby 1.8.6" do version = "1.8.6" lambda { - Mango::Dependencies.send(:check_ruby_version, version) + Mango::Dependencies.check_ruby_version(version) }.should raise_exception(SystemExit, expected_message(version)) end it "aborts for ruby 1.8.7" do version = "1.8.7" lambda { - Mango::Dependencies.send(:check_ruby_version, version) + Mango::Dependencies.check_ruby_version(version) }.should raise_exception(SystemExit, expected_message(version)) end it "aborts for ruby 1.9.0" do version = "1.9.0" lambda { - Mango::Dependencies.send(:check_ruby_version, version) + Mango::Dependencies.check_ruby_version(version) }.should raise_exception(SystemExit, expected_message(version)) end it "aborts for ruby 1.9.1" do version = "1.9.1" lambda { - Mango::Dependencies.send(:check_ruby_version, version) + Mango::Dependencies.check_ruby_version(version) }.should raise_exception(SystemExit, expected_message(version)) end it "doesn't abort for ruby 1.9.2" do version = "1.9.2" lambda { - Mango::Dependencies.send(:check_ruby_version, version) + Mango::Dependencies.check_ruby_version(version) }.should_not raise_exception(SystemExit, expected_message(version)) end end ################################################################################################# - describe ".destroy_warnings" do - it "empties the warnings cache" do - Mango::Dependencies.class_variable_get(:@@warnings_cache).should be_empty - - Mango::Dependencies.create_warning_for(LoadError.new("no such file to load -- yard")) - Mango::Dependencies.class_variable_get(:@@warnings_cache).should_not be_empty - - Mango::Dependencies.destroy_warnings - Mango::Dependencies.class_variable_get(:@@warnings_cache).should be_empty + context "given three load errors" do + before(:each) do + ["rspec/core/rake_task", "yard", "bluecloth"].each do |file| + load_error = LoadError.new("no such file to load -- #{file}") + Mango::Dependencies.create_warning_for(load_error) + end end - end - ################################################################################################# - - describe ".create_warning_for" do after(:each) do Mango::Dependencies.destroy_warnings end - it "creates and caches and cache one warning from a known development gem dependency" do - Mango::Dependencies.create_warning_for(LoadError.new("no such file to load -- yard")) - Mango::Dependencies.class_variable_get(:@@warnings_cache).should == ["yard --version '0.6.1'"] + describe ".destroy_warnings" do + it "empties the warnings cache" do + Mango::Dependencies.class_variable_get(:@@warnings_cache).should_not be_empty + Mango::Dependencies.destroy_warnings + Mango::Dependencies.class_variable_get(:@@warnings_cache).should be_empty + end end - it "creates and caches and cache warnings from all known development gem dependencies" do - Mango::Dependencies::DEVELOPMENT_GEMS.each_key do |file_name| - gem_name = if Mango::Dependencies::FILE_NAME_TO_GEM_NAME.has_key?(file_name) - Mango::Dependencies::FILE_NAME_TO_GEM_NAME[file_name] - else - file_name - end - load_error = LoadError.new("no such file to load -- #{gem_name}") - Mango::Dependencies.create_warning_for(load_error) - end + ############################################################################################### - expected = [ - "rack-test --version '0.5.6'", - "rspec --version '2.0.1'", - "yard --version '0.6.1'", - "yard-sinatra --version '0.5.1'", - "bluecloth --version '2.0.9'" - ] - Mango::Dependencies.class_variable_get(:@@warnings_cache).should == expected + describe ".create_warning_for" do + it "creates and caches three warnings" do + expected = [:"rspec-core", :yard, :bluecloth] + Mango::Dependencies.class_variable_get(:@@warnings_cache).should == expected + end end - it "raises a RuntimeError when creating a warning from an unknown development gem dependency" do - lambda { - Mango::Dependencies.create_warning_for(LoadError.new("no such file to load -- _fakegem")) - }.should raise_exception(RuntimeError, "Cannot create a dependency warning for unknown development gem -- _fakegem") - end - end + ############################################################################################### - ################################################################################################# + describe ".render_warnings" do + before(:each) do + $stdout = StringIO.new + end - describe ".render_warnings" do - before(:each) do - $stdout = StringIO.new - end + after(:each) do + $stdout = STDOUT + end - after(:each) do - $stdout = STDOUT - end + it "displays a warning message to the user on the standard output channel" do + Mango::Dependencies.render_warnings + $stdout.string.should == <<-MESSAGE - it "displays a warning message to the user on the standard output channel" do - Mango::Dependencies.create_warning_for(LoadError.new("no such file to load -- rspec/core/rake_task")) - Mango::Dependencies.create_warning_for(LoadError.new("no such file to load -- yard")) - Mango::Dependencies.create_warning_for(LoadError.new("no such file to load -- bluecloth")) - Mango::Dependencies.render_warnings - $stdout.string.should == <<-MESSAGE +Could not require the following RubyGems: rspec-core, yard, bluecloth +Please run "bundle install" to access all development features. -The following development gem dependencies could not be found. Without them, some available development features are missing: -rspec --version '2.0.1' -yard --version '0.6.1' -bluecloth --version '2.0.9' - MESSAGE - end + MESSAGE + end - it "doesn't display a warning message to the user if there are no warnings in the cache" do - Mango::Dependencies.destroy_warnings - Mango::Dependencies.render_warnings - $stdout.string.should be_empty + it "doesn't display a warning message to the user if there are no warnings in the cache" do + Mango::Dependencies.destroy_warnings + Mango::Dependencies.render_warnings + $stdout.string.should be_empty + end end end #################################################################################################