Permalink
Browse files

Convert tests from cucumber to rspec

  • Loading branch information...
1 parent c703d13 commit ba60e17f01c990b857c5e11cb3110da1fd584c9e @masonforest masonforest committed Dec 20, 2013
View
@@ -7,3 +7,4 @@
pkg
test_project
tmp/aruba
+tmp/dummy
View
@@ -39,6 +39,12 @@ GEM
rspec-expectations (>= 2.7.0)
atomic (1.1.14)
builder (3.1.4)
+ capybara (2.2.0)
+ mime-types (>= 1.16)
+ nokogiri (>= 1.3.3)
+ rack (>= 1.0.0)
+ rack-test (>= 0.5.4)
+ xpath (~> 2.0)
childprocess (0.3.9)
ffi (~> 1.0, >= 1.0.11)
cucumber (1.3.3)
@@ -61,9 +67,12 @@ GEM
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.25.1)
+ mini_portile (0.5.2)
minitest (4.7.5)
multi_json (1.7.7)
multi_test (0.0.1)
+ nokogiri (1.6.1)
+ mini_portile (~> 0.5.0)
polyglot (0.3.3)
rack (1.5.2)
rack-test (0.6.2)
@@ -82,8 +91,14 @@ GEM
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (10.1.0)
+ rspec (2.14.1)
+ rspec-core (~> 2.14.0)
+ rspec-expectations (~> 2.14.0)
+ rspec-mocks (~> 2.14.0)
+ rspec-core (2.14.7)
rspec-expectations (2.14.0)
diff-lcs (>= 1.1.3, < 2.0)
+ rspec-mocks (2.14.4)
sprockets (2.10.1)
hike (~> 1.2)
multi_json (~> 1.0)
@@ -101,12 +116,16 @@ GEM
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.38)
+ xpath (2.0.0)
+ nokogiri (~> 1.3)
PLATFORMS
ruby
x86-mingw32
DEPENDENCIES
aruba (~> 0.5.2)
+ capybara
cucumber (~> 1.2)
+ rspec
suspenders!
View
@@ -1,8 +1,8 @@
require 'bundler/setup'
require 'bundler/gem_tasks'
-require 'cucumber/rake/task'
+require 'rspec/core/rake_task'
-Cucumber::Rake::Task.new
+RSpec::Core::RakeTask.new(:rspec)
desc 'Run the test suite'
-task :default => ['cucumber']
+task :default => :rspec
View
@@ -1,8 +1,6 @@
#!/usr/bin/env ruby
-require File.expand_path(File.join('..', 'lib', 'suspenders', 'generators', 'app_generator'), File.dirname(__FILE__))
-require File.expand_path(File.join('..', 'lib', 'suspenders', 'actions'), File.dirname(__FILE__))
-require File.expand_path(File.join('..', 'lib', 'suspenders', 'app_builder'), File.dirname(__FILE__))
+require File.expand_path(File.join('..', 'lib', 'suspenders'), File.dirname(__FILE__))
if ['create', '--create'].include? ARGV[0]
ARGV.shift
@@ -1,8 +0,0 @@
-@disable-bundler
-Feature: Creating a Github repo
-
- Scenario: --github=organization/project
- When I suspend a project called "test_project" with:
- | argument | value |
- | --github | organization/project |
- Then the "organization/project" Github repo should exist
@@ -1,11 +0,0 @@
-@disable-bundler
-Feature: Creating a Heroku app
-
- Scenario: --heroku=true
- When I suspend a project called "test_project" with:
- | argument | value |
- | --heroku | true |
- Then the "test_project-staging" Heroku app should exist
- And the "test_project-production" Heroku app should exist
- And the "staging" Heroku remote should have "SECRET_KEY_BASE" configured
- And the "production" Heroku remote should have "SECRET_KEY_BASE" configured
@@ -1,44 +0,0 @@
-@disable-bundler
-Feature: Rake works in the suspended project
- Background:
- Given I ensure no databases exist for "test_project"
-
- Scenario: Running rake in the suspended project
- When I suspend a project called "test_project"
- And I cd to the "test_project" root
- And I obtain a fresh checkout
- And I setup the project
- Then I can cleanly rake the project
-
- Scenario: Making a model spec then running rake
- When I suspend a project called "test_project"
- And I cd to the "test_project" root
- And I obtain a fresh checkout
- And I setup the project
- And I generate "model post title:string"
- And I run migrations
- Then I can cleanly rake the project
-
- Scenario: Making a feature spec then running rake
- When I suspend a project called "test_project"
- And I cd to the "test_project" root
- And I obtain a fresh checkout
- And I setup the project
- And I write to "spec/features/example_spec.rb" with:
- """
- require 'spec_helper'
-
- feature 'Example feature spec' do
- scenario 'using a method from the Features module' do
- expect(example_method).to eq('Expected Value')
- end
- end
- """
- And I write to "spec/support/features/example.rb" with:
- """
- module Features
- def example_method
- 'Expected Value'
- end
- end
- """
@@ -1,89 +0,0 @@
-require 'aruba/cucumber'
-
-When 'I run rake' do
- in_current_dir do
- run_simple 'bundle exec rake'
- end
-end
-
-When 'I run migrations' do
- in_current_dir do
- run_simple 'bundle exec rake db:migrate'
- end
-end
-
-When 'I obtain a fresh checkout' do
- in_current_dir do
- run_simple 'git clean --force -x -d'
- end
-end
-
-When 'I run the rake task "$task_name"' do |task_name|
- in_current_dir do
- run_simple "bundle exec rake #{task_name}"
- end
-end
-
-When 'I generate "$generator_with_args"' do |generator_with_args|
- in_current_dir do
- run_simple "bundle exec rails generate #{generator_with_args}"
- end
-end
-
-When 'I ensure no databases exist for "$project_name"' do |project_name|
- run "dropdb #{project_name}_development"
- run "dropdb #{project_name}_test"
-end
-
-When 'I suspend a project called "$project_name"' do |project_name|
- suspenders_bin = File.expand_path(File.join('..', '..', 'bin', 'suspenders'), File.dirname(__FILE__))
- run_simple "#{suspenders_bin} #{project_name}"
- cd project_name
- run_simple 'git add -A'
- run_simple 'git commit -m "Initial commit"'
- cd '..'
-end
-
-When %r{I suspend a project called "([^"]*)" with:} do |project_name, arguments_table|
- suspenders_bin = File.expand_path(File.join('..', '..', 'bin', 'suspenders'), File.dirname(__FILE__))
- arguments = arguments_table.hashes.inject([]) do |accum, argument|
- accum << "#{argument['argument']}=#{argument['value']}"
- end.join
- run_simple "#{suspenders_bin} #{project_name} #{arguments}"
-end
-
-When 'I cd to the "$test_project" root' do |dirname|
- cd dirname
-end
-
-When 'I setup the project' do
- run_simple 'bin/setup'
-end
-
-Then 'I can cleanly rake the project' do
- steps %{
- When I run rake
- }
-end
-
-Then %r{"(.*)" should not be installed} do |gem_name|
- in_current_dir do
- system("bundle show #{gem_name} 2>&1 > /dev/null").should be_false
- end
-end
-
-Then %r{"(.*)" should not be included in "(.*)"} do |content, file_path|
- check_file_content file_path, content, false
-end
-
-Then %r{the "([^"]*)" Heroku app should exist} do |app_name|
- FakeHeroku.should have_created_app(app_name)
-end
-
-Then %r{the "([^"]+)" Heroku remote should have "([^"]+)" configured} do |remote_name, config_name|
- FakeHeroku.configured_vars_for(remote_name).should include(config_name)
-end
-
-Then %r{the "([^"]*)" Github repo should exist} do |repo_name|
- FakeGithub.should have_created_repo(repo_name)
-end
View
@@ -1,11 +0,0 @@
-Before do
- ENV['TESTING'] = 'true'
- ENV['DISABLE_SPRING'] = 'true'
- @aruba_timeout_seconds = 560
-end
-
-After do
- FakeHeroku.clear!
- FakeGithub.clear!
- FileUtils.rm_rf 'test_project'
-end
View
@@ -0,0 +1,3 @@
+require 'suspenders/generators/app_generator'
+require 'suspenders/actions'
+require 'suspenders/app_builder'
@@ -292,7 +292,7 @@ def setup_default_rake_task
def override_path_for_tests
if ENV['TESTING']
- support_bin = File.expand_path(File.join('..', '..', '..', 'features', 'support', 'bin'))
+ support_bin = File.expand_path(File.join('..', '..', 'spec', 'fakes', 'bin'))
"PATH=#{support_bin}:$PATH"
end
end
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,11 @@
+require 'spec_helper'
+
+feature 'github repo' do
+ scenario 'I suspend a project with a git repo specified' do
+ repo_name = 'test'
+ set_command_line_arguments("--github=#{repo_name}")
+ run_suspenders
+
+ expect(FakeGithub).to have_created_repo(repo_name)
+ end
+end
@@ -0,0 +1,15 @@
+require 'spec_helper'
+
+feature 'github repo' do
+ scenario 'I suspend a project with --heroku=true' do
+ repo_name = 'test'
+ set_command_line_arguments("--heroku=true")
+ run_suspenders
+
+ expect(FakeHeroku).to have_created_app("#{SuspendersTestHelpers::APP_NAME}-staging")
+ expect(FakeHeroku).to have_created_app("#{SuspendersTestHelpers::APP_NAME}-production")
+
+ expect(FakeHeroku.configured_vars_for('staging')).to include('SECRET_KEY_BASE')
+ expect(FakeHeroku.configured_vars_for('production')).to include('SECRET_KEY_BASE')
+ end
+end
@@ -0,0 +1,15 @@
+require 'spec_helper'
+
+feature 'suspending a project' do
+ scenario 'creates a new rails project that is configured correctly' do
+ set_command_line_arguments
+ create_tmp_dir
+ run_suspenders
+
+ expect(File).to be_directory(suspended_directory)
+
+ Bundler.with_clean_env do
+ expect(`rake`).to include('0 failures')
+ end
+ end
+end
View
@@ -0,0 +1,22 @@
+require 'capybara/rspec'
+require 'bundler/setup'
+ENV['TEST'] = '1'
+
+require File.expand_path(File.join('..', 'lib', 'suspenders'), File.dirname(__FILE__))
+
+templates_root = File.expand_path(File.join("..", "templates"), File.dirname(__FILE__))
+Suspenders::AppGenerator.source_root templates_root
+Suspenders::AppGenerator.source_paths << Rails::Generators::AppGenerator.source_root << templates_root
+
+Bundler.require(:default, :test)
+
+Dir['./spec/support/**/*.rb'].each { |file| require file }
+
+RSpec.configure do |config|
+ config.include SuspendersTestHelpers
+
+ config.after(:all) do
+ drop_dummy_database
+ clean_suspended_directory
+ end
+end
File renamed without changes.
File renamed without changes.
View
@@ -0,0 +1,41 @@
+module SuspendersTestHelpers
+ APP_NAME = 'dummy'
+
+ def drop_dummy_database
+ Dir.chdir(suspended_directory) do
+ Bundler.with_clean_env do
+ `bundle exec rake db:drop`
+ end
+ end
+ end
+
+ def clean_suspended_directory
+ Dir.chdir(root_path)
+ FileUtils.rm_rf(suspended_directory)
+ end
+
+ def create_tmp_dir
+ FileUtils.mkdir_p("#{root_path}/tmp")
+ end
+
+ def set_command_line_arguments(arguments = nil)
+ arguments = "#{suspended_directory} #{arguments}"
+ ARGV.replace(arguments.split(' '))
+ end
+
+ def run_suspenders
+ Suspenders::AppGenerator.start
+ end
+
+ def suspended_directory
+ @suspended_directory ||= "#{root_path}/tmp/#{APP_NAME}"
+ end
+
+ def template(file)
+ IO.read("#{root_path}/templates/#{file}")
+ end
+
+ def root_path
+ File.expand_path('../../', __FILE__)
+ end
+end
View
@@ -30,4 +30,6 @@ rush to build something amazing; don't use it if you like missing deadlines.
s.summary = "Generate a Rails app using thoughtbot's best practices."
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.version = Suspenders::VERSION
+ s.add_development_dependency 'rspec'
+ s.add_development_dependency 'capybara'
end

0 comments on commit ba60e17

Please sign in to comment.