Skip to content

Commit

Permalink
- upgrade to rspec 2.6
Browse files Browse the repository at this point in the history
- use a gemfile to specify dependencies
  • Loading branch information
smtlaissezfaire committed Jun 6, 2011
1 parent 6068b54 commit 517fa1a
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 31 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
.bundle
1 change: 1 addition & 0 deletions .rspec
@@ -0,0 +1 @@
--color
4 changes: 4 additions & 0 deletions Gemfile
@@ -0,0 +1,4 @@
source :rubygems

gem 'rspec', ">=2.6.0"
gem 'activerecord', ">=3.0.0"
33 changes: 33 additions & 0 deletions Gemfile.lock
@@ -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)
55 changes: 28 additions & 27 deletions spec/smt/improved_mysql_schema_dumper_spec.rb
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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")
Expand Down
2 changes: 0 additions & 2 deletions spec/spec.opts

This file was deleted.

7 changes: 5 additions & 2 deletions spec/spec_helper.rb
@@ -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.