Permalink
Browse files

Merge pull request #2 from unepwcmc/tests

Tests
  • Loading branch information...
2 parents 1b7e196 + 0a35911 commit 2f6e633c505e88a64cf91d9ae9d40b37189b889e @agnessa agnessa committed Apr 12, 2012
View
1 .rspec
@@ -0,0 +1 @@
+--colour
View
18 Gemfile
@@ -38,5 +38,19 @@ gem 'capistrano'
# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'
-gem "jquery-rails"
-gem "rspec-rails", ">= 2.0.1", :group => [:development, :test]
+gem 'jquery-rails'
+gem 'ejs'
+
+gem 'rspec-rails', '~> 2.6', :group => [:development, :test]
+group :test do
+ gem 'capybara'
+ gem 'capybara-webkit'
+ gem 'headless'
+ gem 'database_cleaner'
+
+ gem 'guard-rspec'
+ gem 'shoulda'
+ gem 'factory_girl_rails'
+ gem 'database_cleaner'
+ gem 'launchy'
+end
View
56 Gemfile.lock
@@ -35,6 +35,7 @@ GEM
activesupport (3.2.2)
i18n (~> 0.6)
multi_json (~> 1.0)
+ addressable (2.2.7)
arel (3.0.2)
builder (3.0.0)
capistrano (2.11.2)
@@ -43,18 +44,43 @@ GEM
net-sftp (>= 2.0.0)
net-ssh (>= 2.0.14)
net-ssh-gateway (>= 1.1.0)
+ capybara (1.1.2)
+ mime-types (>= 1.16)
+ nokogiri (>= 1.3.3)
+ rack (>= 1.0.0)
+ rack-test (>= 0.5.4)
+ selenium-webdriver (~> 2.0)
+ xpath (~> 0.1.4)
+ capybara-webkit (0.11.0)
+ capybara (>= 1.0.0, < 1.2)
+ json
+ childprocess (0.3.1)
+ ffi (~> 1.0.6)
coffee-rails (3.2.2)
coffee-script (>= 2.2.0)
railties (~> 3.2.0)
coffee-script (2.2.0)
coffee-script-source
execjs
coffee-script-source (1.2.0)
+ database_cleaner (0.7.2)
diff-lcs (1.1.3)
ejs (1.0.0)
erubis (2.7.0)
execjs (1.3.0)
multi_json (~> 1.0)
+ factory_girl (3.1.0)
+ activesupport (>= 3.0.0)
+ factory_girl_rails (3.1.0)
+ factory_girl (~> 3.1.0)
+ railties (>= 3.0.0)
+ ffi (1.0.11)
+ guard (1.0.1)
+ ffi (>= 0.5.0)
+ thor (~> 0.14.6)
+ guard-rspec (0.7.0)
+ guard (>= 0.10.0)
+ headless (0.3.1)
highline (1.6.11)
hike (1.2.1)
i18n (0.6.0)
@@ -63,7 +89,11 @@ GEM
railties (>= 3.2.0, < 5.0)
thor (~> 0.14)
json (1.6.6)
+ launchy (2.1.0)
+ addressable (~> 2.2.6)
libv8 (3.3.10.4)
+ libwebsocket (0.1.3)
+ addressable
mail (2.4.4)
i18n (>= 0.4.0)
mime-types (~> 1.16)
@@ -77,6 +107,7 @@ GEM
net-ssh (2.3.0)
net-ssh-gateway (1.1.0)
net-ssh (>= 1.99.1)
+ nokogiri (1.5.2)
polyglot (0.3.3)
rack (1.4.1)
rack-cache (1.2)
@@ -120,11 +151,23 @@ GEM
activesupport (>= 3.0)
railties (>= 3.0)
rspec (~> 2.9.0)
+ rubyzip (0.9.7)
sass (3.1.15)
sass-rails (3.2.5)
railties (~> 3.2.0)
sass (>= 3.1.10)
tilt (~> 1.3)
+ selenium-webdriver (2.21.0)
+ childprocess (>= 0.2.5)
+ ffi (~> 1.0)
+ libwebsocket (~> 0.1.3)
+ multi_json (~> 1.0)
+ rubyzip
+ shoulda (3.0.1)
+ shoulda-context (~> 1.0.0)
+ shoulda-matchers (~> 1.0.0)
+ shoulda-context (1.0.0)
+ shoulda-matchers (1.0.0)
sprockets (2.1.2)
hike (~> 1.2)
rack (~> 1.0)
@@ -141,19 +184,30 @@ GEM
uglifier (1.2.4)
execjs (>= 0.3.0)
multi_json (>= 1.0.2)
+ xpath (0.1.4)
+ nokogiri (~> 1.3)
PLATFORMS
ruby
DEPENDENCIES
bootstrap-generators (~> 2.0)!
capistrano
+ capybara
+ capybara-webkit
coffee-rails (~> 3.2.1)
+ database_cleaner
+ ejs
+ factory_girl_rails
+ guard-rspec
+ headless
jquery-rails
+ launchy
rails (= 3.2.2)
rails-backbone
- rspec-rails (>= 2.0.1)
+ rspec-rails (~> 2.6)
sass-rails (~> 3.2.3)
+ shoulda
sqlite3
therubyracer
uglifier (>= 1.0.3)
View
19 Guardfile
@@ -0,0 +1,19 @@
+# A sample Guardfile
+# More info at https://github.com/guard/guard#readme
+
+guard 'rspec', :version => 2 do
+ watch(%r{^spec/.+_spec\.rb$})
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
+ watch('spec/spec_helper.rb') { "spec" }
+
+ # Rails example
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
+ watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
+ watch('config/routes.rb') { "spec/routing" }
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
+ # Capybara request specs
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
+end
+
View
12 spec/controllers/indicators_controller_spec.rb
@@ -1,12 +0,0 @@
-require 'spec_helper'
-
-describe IndicatorsController do
-
- describe "GET 'index'" do
- it "returns http success" do
- get 'index'
- response.should be_success
- end
- end
-
-end
View
13 spec/factories.rb
@@ -0,0 +1,13 @@
+FactoryGirl.define do
+ # Goal
+ factory :goal do
+ end
+
+ # Indicator
+ factory :indicator do
+ end
+
+ # Target
+ factory :target do
+ end
+end
View
15 spec/helpers/indicators_helper_spec.rb
@@ -1,15 +0,0 @@
-require 'spec_helper'
-
-# Specs in this file have access to a helper object that includes
-# the IndicatorsHelper. For example:
-#
-# describe IndicatorsHelper do
-# describe "string concat" do
-# it "concats two strings with spaces" do
-# helper.concat_strings("this","that").should == "this that"
-# end
-# end
-# end
-describe IndicatorsHelper do
- pending "add some examples to (or delete) #{__FILE__}"
-end
View
2 spec/models/focal_area_spec.rb
@@ -1,5 +1,5 @@
require 'spec_helper'
describe FocalArea do
- pending "add some examples to (or delete) #{__FILE__}"
+ it { should have_and_belong_to_many(:indicators) }
end
View
2 spec/models/goal_spec.rb
@@ -1,5 +1,5 @@
require 'spec_helper'
describe Goal do
- pending "add some examples to (or delete) #{__FILE__}"
+ it { should have_many(:targets) }
end
View
2 spec/models/headline_spec.rb
@@ -1,5 +1,5 @@
require 'spec_helper'
describe Headline do
- pending "add some examples to (or delete) #{__FILE__}"
+ it { should have_many(:indicators) }
end
View
10 spec/models/indicator_spec.rb
@@ -1,5 +1,13 @@
require 'spec_helper'
describe Indicator do
- pending "add some examples to (or delete) #{__FILE__}"
+ it { should belong_to(:headline) }
+ it { should have_and_belong_to_many(:targets) }
+ it { should have_and_belong_to_many(:focal_areas) }
+ it { should have_and_belong_to_many(:partners) }
+
+ it 'should return a link composed by bipindicators.net and #rel_link' do
+ indicator = FactoryGirl.create(:indicator, rel_link: 'abc')
+ indicator.link.should eq('http://www.bipindicators.net/abc')
+ end
end
View
2 spec/models/partner_spec.rb
@@ -1,5 +1,5 @@
require 'spec_helper'
describe Partner do
- pending "add some examples to (or delete) #{__FILE__}"
+ it { should have_and_belong_to_many(:indicators) }
end
View
3 spec/models/target_spec.rb
@@ -1,5 +1,6 @@
require 'spec_helper'
describe Target do
- pending "add some examples to (or delete) #{__FILE__}"
+ it { should belong_to(:goal) }
+ it { should have_and_belong_to_many(:indicators) }
end
View
81 spec/requests/indicators_spec.rb
@@ -0,0 +1,81 @@
+require 'spec_helper'
+
+describe 'indicators' do
+ describe 'GET /' do
+ it 'works!' do
+ visit '/'
+ page.driver.response.status.should be(200)
+ end
+
+ it 'has the matrix tab selected by default' do
+ visit '/'
+ page.find('ul.nav li:first')['class'].should eq('active')
+ page.find('#matrix')['class'].should eq('tab-pane active')
+ end
+
+ it 'changes #graphic tab to selected when clicking on the it', js: true do
+ visit '/'
+ click_link('Graphic')
+ page.find('ul.nav li + li')['class'].should eq('active')
+ page.find('#graphic')['class'].should eq('tab-pane active')
+ end
+
+ it 'changes #headlines tab to selected when clicking on the it', js: true do
+ visit '/'
+ click_link('Headlines')
+ page.find('ul.nav li:last')['class'].should eq('active')
+ page.find('#headlines')['class'].should eq('tab-pane active')
+ end
+
+ it 'does not show any indicators by default on the matrix tab', js: true do
+ FactoryGirl.create(:indicator, title: 'The most indicator of the world')
+
+ visit '/'
+ page.find('#indicators').should_not have_content('The most indicator of the world')
+ end
+
+ it 'does not show any indicators by default on the graphic tab', js: true do
+ FactoryGirl.create(:indicator, title: 'The most indicator of the world')
+
+ visit '/'
+ click_link('Graphic')
+ page.find('#indicators').should_not have_content('The most indicator of the world')
+ end
+
+ it 'does not show any indicators by default on the headlines tab', js: true do
+ FactoryGirl.create(:indicator, title: 'The most indicator of the world')
+
+ visit '/'
+ click_link('Headlines')
+ page.find('#indicators').should_not have_content('The most indicator of the world')
+ end
+
+ describe 'goals list' do
+ it 'shows goal`s code', js: true do
+ FactoryGirl.create(:goal, code: 'ABBA')
+
+ visit '/'
+ page.find('#matrix').should have_content('ABBA')
+ end
+
+ describe 'targets list' do
+ it 'shows target`s keyword', js: true do
+ goal = FactoryGirl.create(:goal, code: 'ABBA')
+ FactoryGirl.create(:target, keyword: 'ABC', goal: goal)
+
+ visit '/'
+ page.find('#matrix').should have_content('ABC')
+ end
+ end
+ end
+
+ describe 'graph' do
+ end
+
+ describe 'headlines list' do
+ end
+
+ describe 'indicators list' do
+ end
+ end
+end
View
42 spec/spec_helper.rb
@@ -0,0 +1,42 @@
+# This file is copied to spec/ when you run 'rails generate rspec:install'
+ENV["RAILS_ENV"] ||= 'test'
+require File.expand_path("../../config/environment", __FILE__)
+require 'rspec/rails'
+require 'capybara/rspec'
+require 'capybara-webkit'
+require 'headless'
+require 'database_cleaner'
+
+# Requires supporting ruby files with custom matchers and macros, etc,
+# in spec/support/ and its subdirectories.
+Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
+
+RSpec.configure do |config|
+ # ## Mock Framework
+ #
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
+ #
+ # config.mock_with :mocha
+ # config.mock_with :flexmock
+ # config.mock_with :rr
+
+ # If true, the base class of anonymous controllers will be inferred
+ # automatically. This will be the default behavior in future versions of
+ # rspec-rails.
+ config.infer_base_class_for_anonymous_controllers = false
+
+ config.before(:suite) do
+ # Use the headless gem to manage your Xvfb server
+ # Do not destroy X server incase another process is using it
+ Headless.new(:destroy_on_exit => false).start
+ DatabaseCleaner.strategy = :truncation
+ end
+
+ config.before(:each) do
+ DatabaseCleaner.start
+ end
+
+ config.after(:each) do
+ DatabaseCleaner.clean
+ end
+end
View
0 spec/support/.gitkeep
No changes.
View
1 spec/support/env.rb
@@ -0,0 +1 @@
+Capybara.javascript_driver = :webkit
View
5 spec/views/indicators/index.html.erb_spec.rb
@@ -1,5 +0,0 @@
-require 'spec_helper'
-
-describe "indicators/index.html.erb" do
- pending "add some examples to (or delete) #{__FILE__}"
-end

0 comments on commit 2f6e633

Please sign in to comment.