Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Test coverage for jballanc/index-fixup

Add test coverage for the case of too many gems to be bothered listing.
  • Loading branch information...
commit b70ceabd198ca7b99b166b01234193554a2242a7 1 parent ed8127e
Tom Lea cwninja authored
3  geminabox.gemspec
View
@@ -22,4 +22,7 @@ Gem::Specification.new do |s|
s.add_development_dependency('rake')
s.add_development_dependency('rack-test')
s.add_development_dependency('minitest')
+ s.add_development_dependency('capybara')
+ s.add_development_dependency('capybara-mechanize')
+ s.add_development_dependency('pry')
end
BIN  test/fixtures/large_gem_list_test.fixture
View
Binary file not shown
48 test/integration/web_interface/large_gem_list_test.rb
View
@@ -0,0 +1,48 @@
+require 'test_helper'
+require 'minitest/unit'
+require 'rack/test'
+
+class LargeGemListSpec < Geminabox::TestCase
+ include Capybara::DSL
+
+ test "more than 5 versions of the same gem" do
+ cache_fixture_data_dir('large_gem_list_test') do
+ assert_can_push(:unrelated_gem, :version => '1.0')
+
+ assert_can_push(:my_gem, :version => '1.0')
+ assert_can_push(:my_gem, :version => '2.0')
+ assert_can_push(:my_gem, :version => '3.0')
+ assert_can_push(:my_gem, :version => '4.0')
+ assert_can_push(:my_gem, :version => '5.0')
+ assert_can_push(:my_gem, :version => '6.0')
+ end
+
+ visit url_for("/")
+
+ assert_equal gems_on_page, %w[
+ my_gem-6.0
+ my_gem-5.0
+ my_gem-4.0
+ my_gem-3.0
+ my_gem-2.0
+ unrelated_gem-1.0
+ ]
+
+ page.click_link 'Older versions...'
+
+ assert_equal gems_on_page, %w[
+ my_gem-6.0
+ my_gem-5.0
+ my_gem-4.0
+ my_gem-3.0
+ my_gem-2.0
+ my_gem-1.0
+ ]
+ end
+
+ def gems_on_page
+ page.all('a.download').
+ map{|el| el['href'] }.
+ map{|url| url.split("/").last.gsub(/\.gem$/, '') }
+ end
+end
7 test/test_helper.rb
View
@@ -7,7 +7,14 @@
require 'fileutils'
require 'test_support/gem_factory'
require 'test_support/geminabox_test_case'
+require 'pry'
+require 'capybara/mechanize'
+require 'capybara/dsl'
+
+
+Capybara.default_driver = :mechanize
+Capybara.app_host = "http://localhost"
module TestMethodMagic
def test(test_name, &block)
define_method "test: #{test_name} ", &block
24 test/test_support/geminabox_test_case.rb
View
@@ -110,6 +110,28 @@ def find_free_port
port
end
+ FIXTURES_PATH = Pathname.new(File.expand_path("../../fixtures", __FILE__))
+ def load_fixture_data_dir(name)
+ path = FIXTURES_PATH.join("#{name}.fixture")
+ FileUtils.rm_rf config.data
+ FileUtils.mkdir_p config.data
+
+ Dir.chdir config.data do
+ system "tar", "-xf", path.to_s
+ end
+ end
+
+ def cache_fixture_data_dir(name)
+ path = FIXTURES_PATH.join("#{name}.fixture")
+ if File.exists? path
+ load_fixture_data_dir(name)
+ else
+ yield
+ Dir.chdir config.data do
+ system "tar", "-cf", path.to_s, *Dir.glob('{*,**/*}')
+ end
+ end
+ end
def start_app!
clean_data_dir
@@ -120,7 +142,7 @@ def start_app!
:AccessLog => [],
:Logger => WEBrick::Log::new("/dev/null", 7)
}
-
+
if config.ssl
server_options.merge!(
:SSLEnable => true,
Please sign in to comment.
Something went wrong with that request. Please try again.