diff --git a/Rakefile b/Rakefile index f0cb5e54..d818d311 100644 --- a/Rakefile +++ b/Rakefile @@ -16,6 +16,11 @@ namespace :test do test.pattern = 'test/unit/*_test.rb' test.verbose = true end + Rake::TestTask.new(:integration) do |test| + test.libs << 'lib' << 'test' + test.pattern = 'test/integration/*_test.rb' + test.verbose = true + end end # Generate documentation diff --git a/test/fixtures/articles/1.json b/test/fixtures/articles/1.json new file mode 100644 index 00000000..0e9f34d5 --- /dev/null +++ b/test/fixtures/articles/1.json @@ -0,0 +1 @@ +{"title" : "One", "tags" : ["ruby"]} diff --git a/test/fixtures/articles/2.json b/test/fixtures/articles/2.json new file mode 100644 index 00000000..2c50e5a0 --- /dev/null +++ b/test/fixtures/articles/2.json @@ -0,0 +1 @@ +{"title" : "Two", "tags" : ["ruby", "python"]} diff --git a/test/fixtures/articles/3.json b/test/fixtures/articles/3.json new file mode 100644 index 00000000..0f8726fd --- /dev/null +++ b/test/fixtures/articles/3.json @@ -0,0 +1 @@ +{"title" : "Three", "tags" : ["java"]} diff --git a/test/fixtures/articles/4.json b/test/fixtures/articles/4.json new file mode 100644 index 00000000..b7c4acac --- /dev/null +++ b/test/fixtures/articles/4.json @@ -0,0 +1 @@ +{"title" : "Four", "tags" : ["erlang"]} diff --git a/test/fixtures/articles/5.json b/test/fixtures/articles/5.json new file mode 100644 index 00000000..9d48c2d4 --- /dev/null +++ b/test/fixtures/articles/5.json @@ -0,0 +1 @@ +{"title" : "Five", "tags" : ["javascript", "java"]} diff --git a/test/test_helper.rb b/test/test_helper.rb index 8bdcdb4e..23522c4f 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,9 +1,40 @@ -$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) - require 'rubygems' require 'test/unit' require 'shoulda' require 'mocha' require 'turn' unless ENV["TM_FILEPATH"] +require 'pathname' require 'slingshot' + +class Test::Unit::TestCase + + def fixtures_path + Pathname( File.expand_path( 'fixtures', File.dirname(__FILE__) ) ) + end + + def fixture_file(path) + File.read File.expand_path( path, fixtures_path ) + end + +end + +module Test::Integration + URL = "http://localhost:9200" + + def setup + ::RestClient.delete "#{URL}/articles-test" rescue nil + ::RestClient.post "#{URL}/articles-test", '' + fixtures_path.join('articles').entries.each do |f| + filename = f.to_s + next if filename =~ /^\./ + ::RestClient.put "#{URL}/articles-test/article/#{File.basename(filename, '.*')}", + fixtures_path.join('articles').join(f).read + end + ::RestClient.post "#{URL}/articles-test/_refresh", '' + end + + def teardown + ::RestClient.delete "#{URL}/articles-test" rescue nil + end +end