Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

#2 Add initial specs for Projects and Project

VCR is still missing from the game as I wanted to
focus on getting a feeling for how to write the
tests first. Once we can agree on the current style
or any changes to that, I'll activate VCR.
  • Loading branch information...
commit bdf1138b65044b4268b9548514a8a12b1af92bd8 1 parent 4ff6270
@snusnu snusnu authored
View
1  lingohub.gemspec
@@ -25,4 +25,5 @@ Gem::Specification.new do |gem|
gem.add_development_dependency('taps', '~> 0.3.23')
gem.add_development_dependency('webmock', '~> 1.8.0')
gem.add_development_dependency('i18n', '~> 0.6.0')
+ gem.add_development_dependency('vcr', '~> 2.0.0')
end
View
64 spec/integration/lingohub/models/project_spec.rb
@@ -0,0 +1,64 @@
+require 'spec_helper'
+
+describe Lingohub::Models::Project do
+
+ describe '#initialize' do
+
+ subject { projects[title] }
+
+ let(:projects) { Lingohub::Spec.projects }
+ let(:owner) { Lingohub::Spec.credentials[:username] }
+ let(:title) { 'Test' }
+ let(:title_slug) { title.downcase }
+ let(:link) { Lingohub::Spec.project_link(title_slug) }
+ let(:weburl) { Lingohub::Spec.weburl(title_slug) }
+ let(:resources_url) { "#{link}/resources" }
+ let(:collaborators_url) { "#{link}/collaborators" }
+ let(:invitations_url) { "#{link}/invitations" }
+ let(:translations_url) { "#{link}/translations" }
+ let(:search_url) { "#{link}/resources/search" }
+ let(:translations_count) { 0 }
+
+ before do
+ projects.create(title)
+ end
+
+ after do
+ projects[title].destroy
+ end
+
+ its(:owner) { should == owner }
+ its(:title) { should == title }
+ its(:link) { should == link }
+ its(:weburl) { should == weburl }
+ its(:resources_url) { should == resources_url }
+ its(:collaborators_url) { should == collaborators_url }
+ its(:invitations_url) { should == invitations_url }
+ its(:translations_url) { should == translations_url }
+ its(:search_url) { should == search_url }
+
+ its(:translations_count) do
+ pending 'this should imo return 0 but returns nil instead'
+ should == translations_count
+ end
+
+ end
+
+ describe '#destroy' do
+
+ subject { project.destroy }
+
+ let(:project) { projects[title] }
+ let(:projects) { Lingohub::Spec.projects }
+ let(:title) { 'Test' }
+
+ before do
+ projects.create(title)
+ end
+
+ it 'should destroy the project' do
+ subject
+ Lingohub::Spec.projects.all.should be_empty
+ end
+ end
+end
View
73 spec/integration/lingohub/models/projects_spec.rb
@@ -0,0 +1,73 @@
+require 'spec_helper'
+
+describe Lingohub::Models::Projects do
+
+ let(:projects) { Lingohub::Spec.projects }
+ let(:title) { 'Test' }
+
+ describe '#create' do
+ subject { projects.create(title) }
+
+ after do
+ projects[title].destroy
+ end
+
+ it 'creates the project on the server' do
+ subject
+ projects[title].should be_instance_of(Lingohub::Models::Project)
+ end
+ end
+
+ describe '#[]' do
+ subject { projects[title] }
+
+ context 'with no projects defined' do
+ it { should be_nil }
+ end
+
+ context 'with projects defined' do
+
+ before do
+ projects.create(title)
+ end
+
+ after do
+ projects[title].destroy
+ end
+
+ it { should be_instance_of(Lingohub::Models::Project) }
+
+ it 'returns the available project' do
+ subject.title.should == title
+ end
+ end
+ end
+
+ describe '#all' do
+
+ subject { projects.all }
+
+ context 'with no projects defined' do
+ it { should be_empty }
+ end
+
+ context 'with projects defined' do
+
+ let(:project) { subject[title] }
+
+ before do
+ projects.create(title)
+ end
+
+ after do
+ projects[title].destroy
+ end
+
+ it { should_not be_empty }
+
+ it 'returns the available project' do
+ project.title.should == title
+ end
+ end
+ end
+end
View
53 spec/spec_helper.rb
@@ -1,11 +1,50 @@
-require "bundler/setup"
-
+require 'rubygems'
require "rspec"
-require "support/matchers"
-$LOAD_PATH.unshift File.join(File.dirname(__FILE__), "../")
-require "lib/lingohub"
+require 'lingohub'
+require 'lingohub/command'
+
+#require 'vcr'
+#VCR.configure do |c|
+# c.cassette_library_dir = 'spec/cassettes'
+# c.hook_into :webmock
+# c.configure_rspec_metadata!
+#end
+
+RSpec.configure do |c|
+ # so we can use `:vcr` rather than `:vcr => true`;
+ # in RSpec 3 this will no longer be necessary.
+ c.treat_symbols_as_metadata_keys_with_true_values = true
+end
+
+module Lingohub
+ module Spec
-RSpec.configure do |config|
- config.include NewGem::Spec::Matchers
+ def self.projects
+ Lingohub::Models::Projects.new(client)
+ end
+
+ def self.client
+ Lingohub::Client.new(credentials)
+ end
+
+ #FIXME change this to something properly setup for spec runs
+ def self.credentials
+ {
+ :username => 'foo',
+ :password => 'bar',
+ :auth_token => '89111d2469b74f7728a2bcee6b5bbb50ce25e13b435a60f9fbc4218e5a990045',
+ :host => 'localhost:3000'
+ }
+ end
+
+ def self.project_link(title)
+ "http://#{credentials[:host]}/api/v1/snusnu/#{title}"
+ end
+
+ def self.weburl(title)
+ "http://#{credentials[:host]}/snusnu/#{title}/translations"
+ end
+ end
end
+
Please sign in to comment.
Something went wrong with that request. Please try again.