Permalink
Browse files

- upgrade to rspec 2.6

- use a gemfile to specify dependencies
  • Loading branch information...
smtlaissezfaire committed Jun 6, 2011
1 parent 6068b54 commit 517fa1a56d1b3091e21a97472796cb2269932172
Showing with 72 additions and 31 deletions.
  1. +1 −0 .gitignore
  2. +1 −0 .rspec
  3. +4 −0 Gemfile
  4. +33 −0 Gemfile.lock
  5. +28 −27 spec/smt/improved_mysql_schema_dumper_spec.rb
  6. +0 −2 spec/spec.opts
  7. +5 −2 spec/spec_helper.rb
View
@@ -0,0 +1 @@
+.bundle
View
1 .rspec
@@ -0,0 +1 @@
+--color
View
@@ -0,0 +1,4 @@
+source :rubygems
+
+gem 'rspec', ">=2.6.0"
+gem 'activerecord', ">=3.0.0"
View
@@ -0,0 +1,33 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ activemodel (3.0.7)
+ activesupport (= 3.0.7)
+ builder (~> 2.1.2)
+ i18n (~> 0.5.0)
+ activerecord (3.0.7)
+ activemodel (= 3.0.7)
+ activesupport (= 3.0.7)
+ arel (~> 2.0.2)
+ tzinfo (~> 0.3.23)
+ activesupport (3.0.7)
+ arel (2.0.10)
+ builder (2.1.2)
+ diff-lcs (1.1.2)
+ i18n (0.5.0)
+ rspec (2.6.0)
+ rspec-core (~> 2.6.0)
+ rspec-expectations (~> 2.6.0)
+ rspec-mocks (~> 2.6.0)
+ rspec-core (2.6.3)
+ rspec-expectations (2.6.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.6.0)
+ tzinfo (0.3.27)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ activerecord (>= 3.0.0)
+ rspec (>= 2.6.0)
@@ -5,26 +5,27 @@ module SMT
it "should have dump as a singleton method" do
ImprovedMysqlSchemaDumper.should respond_to(:dump)
end
-
+
describe "ar_base" do
before :each do
ImprovedMysqlSchemaDumper.reset_ar_base!
end
-
+
it "should be ActiveRecord::Base by default" do
ImprovedMysqlSchemaDumper.ar_base.should == ActiveRecord::Base
end
-
+
it "should allow setting to a mock" do
a_mock = mock 'a mock ar::base class'
ImprovedMysqlSchemaDumper.ar_base = a_mock
ImprovedMysqlSchemaDumper.ar_base.should == a_mock
end
end
-
+
describe "configuration" do
before :each do
- @ar_base = mock('ar base', { :configurations => {
+ @ar_base = mock('ar base', {
+ :configurations => {
"development" => {
"encoding"=>"utf8",
"username"=>"root",
@@ -36,52 +37,52 @@ module SMT
}})
ImprovedMysqlSchemaDumper.ar_base = @ar_base
end
-
+
it "should be the configuration in dev mode" do
ImprovedMysqlSchemaDumper.configuration.should == @ar_base.configurations["development"]
end
-
+
it "should have the username" do
ImprovedMysqlSchemaDumper.database_username.should == "root"
end
-
+
it "should have the database host" do
ImprovedMysqlSchemaDumper.database_host.should == "localhost"
end
-
+
it "should have the database password" do
ImprovedMysqlSchemaDumper.database_password.should be_nil
end
-
+
it "should have the database name" do
ImprovedMysqlSchemaDumper.database_name.should == "development"
end
end
-
+
describe "dump command" do
before :each do
@file_path = "/foo/bar"
- @ar_base = mock 'ar base', :null_object => true
+ @ar_base = mock('ar base').as_null_object
ImprovedMysqlSchemaDumper.ar_base = @ar_base
end
-
+
it "should contain the host" do
ImprovedMysqlSchemaDumper.stub!(:database_host).and_return "localhost"
ImprovedMysqlSchemaDumper.dump_command(@file_path).should include("-h localhost")
end
-
+
it "should not contain any newlines" do
ImprovedMysqlSchemaDumper.dump_command(@file_path).should_not include("\n")
end
-
+
it "should not contain extra spaces" do
ImprovedMysqlSchemaDumper.dump_command(@file_path).should_not include(" ")
end
-
+
it "should quote the filename" do
ImprovedMysqlSchemaDumper.dump_command(@file_path).should include("> '#{@file_path}'")
end
-
+
it "should include mysqldump -u root -h localhost" do
configuration = {
"username" => "root",
@@ -90,7 +91,7 @@ module SMT
@ar_base.stub!(:configurations).and_return({ "development" => configuration })
ImprovedMysqlSchemaDumper.dump_command(@file_path).should include("mysqldump -u root -h localhost")
end
-
+
it "should include the password, if there is one" do
configuration = {
"username" => "root",
@@ -100,8 +101,8 @@ module SMT
@ar_base.stub!(:configurations).and_return({ "development" => configuration })
ImprovedMysqlSchemaDumper.dump_command(@file_path).should include("-pfoo")
end
-
-
+
+
it "should not include the password if there isn't one" do
configuration = {
"username" => "root",
@@ -116,38 +117,38 @@ module SMT
end
end
end
-
+
describe "load" do
before :each do
@ar_base_connection = mock 'ar base connection', :execute => nil
@ar_base = mock 'ar base', :connection => @ar_base_connection
ImprovedMysqlSchemaDumper.ar_base = @ar_base
-
+
@a_file = mock 'a file'
File.stub!(:read).and_return "a string"
end
-
+
it "should have the AR BASE connection" do
ImprovedMysqlSchemaDumper.connection.should == @ar_base_connection
end
-
+
it "should open the file" do
File.should_receive(:read).with(@a_file).and_return "some string"
ImprovedMysqlSchemaDumper.load(@a_file)
end
-
+
it "should execute a single string" do
File.stub!(:read).and_return "a string"
@ar_base_connection.should_receive(:execute).with('a string')
ImprovedMysqlSchemaDumper.load(@a_file)
end
-
+
it "should execute a string spanning multiple lines" do
File.stub!(:read).and_return "foo\nbar\nbaz"
@ar_base_connection.should_receive(:execute).with("foo\nbar\nbaz")
ImprovedMysqlSchemaDumper.load(@a_file)
end
-
+
it "should execute multiple statements, split by semi-colons" do
File.stub!(:read).and_return "foo;\nbar;"
@ar_base_connection.should_receive(:execute).with("foo")
View
@@ -1,2 +0,0 @@
---color
---format progress
View
@@ -1,3 +1,6 @@
-require "rubygems"
-require "spec"
+require 'rubygems'
require File.dirname(__FILE__) + "/../lib/smt"
+
+RSpec.configure do |config|
+ config.mock_with :rspec
+end

0 comments on commit 517fa1a

Please sign in to comment.