Permalink
Browse files

update to use rspec

  • Loading branch information...
1 parent 7bbd476 commit 984f35fc91ff7247d22842b26b1c2e25bf4afdb0 Ryan Sonnek committed Aug 29, 2011
Showing with 97 additions and 57 deletions.
  1. +3 −0 .rspec
  2. +5 −0 .rvmrc
  3. +4 −0 Rakefile
  4. +4 −0 acts_as_stripped.gemspec
  5. +2 −0 lib/acts_as_stripped.rb
  6. +32 −0 spec/acts_as_stripped_spec.rb
  7. +3 −0 spec/database.yml
  8. +44 −0 spec/spec_helper.rb
  9. +0 −39 test/acts_as_stripped_test.rb
  10. +0 −3 test/database.yml
  11. +0 −15 test/test_helper.rb
View
3 .rspec
@@ -0,0 +1,3 @@
+--colour
+--format documentation
+--backtrace
View
5 .rvmrc
@@ -0,0 +1,5 @@
+rvm use ree-1.8.7-2011.03@acts_as_stripped --create
+if ! command -v bundle ; then
+ gem install bundler
+ bundle
+fi
View
4 Rakefile
@@ -1,2 +1,6 @@
require 'bundler'
Bundler::GemHelper.install_tasks
+
+require 'rspec/core/rake_task'
+RSpec::Core::RakeTask.new('spec')
+task :default => :spec
View
4 acts_as_stripped.gemspec
@@ -11,6 +11,10 @@ Gem::Specification.new do |s|
s.summary = %q{strip whitespace from string attributes}
s.description = %q{ ActiveRecord Extension to strip whitespace from attributes before saving values }
+ s.add_runtime_dependency 'activerecord', ['>= 2.0']
+ s.add_development_dependency %q<rspec>, ['>= 2.5.0']
+ s.add_development_dependency(%q<sqlite3-ruby>, ["~> 1.3.2"])
+
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
View
2 lib/acts_as_stripped.rb
@@ -1,3 +1,5 @@
+require 'active_record'
+
module ActsAsStripped
module ClassMethods
def acts_as_stripped(*attrs)
View
32 spec/acts_as_stripped_spec.rb
@@ -0,0 +1,32 @@
+require 'spec_helper'
+
+class Post < ActiveRecord::Base
+ acts_as_stripped :title
+end
+
+describe ActsAsStripped do
+ context 'a basic post instance' do
+ before do
+ @post = Post.new
+ end
+ it 'strips whitespace from title' do
+ @post.title = ' hello world '
+ @post.save!
+
+ @post.title.should == 'hello world'
+ end
+ it 'does not strip whitespace from body' do
+ @post.body = ' awesome '
+ @post.save!
+
+ @post.body.should == ' awesome '
+ end
+ it 'does not fail if title is nil' do
+ @post.title = nil
+ lambda do
+ @post.save!
+ end.should_not raise_error
+ @post.title.should be_nil
+ end
+ end
+end
View
3 spec/database.yml
@@ -0,0 +1,3 @@
+sqlite:
+ adapter: sqlite3
+ database: acts_as_stripped.sqlite3
View
44 spec/spec_helper.rb
@@ -0,0 +1,44 @@
+require 'rubygems'
+require 'bundler/setup'
+
+require 'acts_as_stripped'
+require 'logger'
+
+# 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}
+
+# include Devise::TestHelpers
+
+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
+ config.mock_with :rspec
+
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
+ # config.fixture_path = "#{::Rails.root}/spec/fixtures"
+
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
+ # examples within a transaction, remove the following line or assign false
+ # instead of true.
+ # config.use_transactional_fixtures = true
+
+ config.before(:suite) do
+ puts 'setting up database'
+ config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
+ ActiveRecord::Base.logger = Logger.new STDOUT
+ ActiveRecord::Base.establish_connection(config[ENV['DB'] || 'sqlite'])
+
+ ActiveRecord::Schema.define(:version => 1) do
+ create_table :posts, :force => true do |t|
+ t.column :title, :string
+ t.column :body, :string
+ end
+ end
+ end
+end
View
39 test/acts_as_stripped_test.rb
@@ -1,39 +0,0 @@
-require 'test_helper'
-
-ActiveRecord::Schema.define(:version => 1) do
- create_table :posts, :force => true do |t|
- t.column :title, :string
- t.column :body, :string
- end
-end
-
-class Post < ActiveRecord::Base
- acts_as_stripped :title
-end
-
-class ActsAsStrippedTest < Test::Unit::TestCase
- context 'a basic post instance' do
- setup do
- @post = Post.new
- end
- should 'strip whitespace from title' do
- @post.title = ' hello world '
- @post.save!
-
- assert_equal 'hello world', @post.title
- end
- should 'not strip whitespace from body' do
- @post.body = ' awesome '
- @post.save!
-
- assert_equal ' awesome ', @post.body
- end
- should 'not fail if title is nil' do
- @post.title = nil
- assert_nothing_raised do
- @post.save!
- end
- assert_nil @post.title
- end
- end
-end
View
3 test/database.yml
@@ -1,3 +0,0 @@
-sqlite:
- :adapter: sqlite3
- :dbfile: acts_as_stripped.sqlite3
View
15 test/test_helper.rb
@@ -1,15 +0,0 @@
-require 'rubygems'
-require 'test/unit'
-require 'shoulda'
-require 'activerecord'
-
-$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
-$LOAD_PATH.unshift(File.dirname(__FILE__))
-require 'acts_as_stripped'
-
-config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
-ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
-ActiveRecord::Base.establish_connection(config[ENV['DB'] || 'sqlite'])
-
-class Test::Unit::TestCase
-end

0 comments on commit 984f35f

Please sign in to comment.