Skip to content
This repository
Browse code

set up initial rspec spec

  • Loading branch information...
commit fc51f155d6534250c187c4d56120377ecd02230f 1 parent 9d54250
Doug Cole authored January 29, 2012
1  .rspec
... ...
@@ -0,0 +1 @@
  1
+--colour
30  Gemfile.lock
@@ -100,7 +100,7 @@ GEM
100 100
     delayed_job (2.1.4)
101 101
       activesupport (~> 3.0)
102 102
       daemons
103  
-    diff-lcs (1.1.2)
  103
+    diff-lcs (1.1.3)
104 104
     em-websocket (0.2.1)
105 105
       addressable (>= 2.1.1)
106 106
       eventmachine (>= 0.12.9)
@@ -208,7 +208,7 @@ GEM
208 208
     pg (0.11.0)
209 209
     polyglot (0.3.1)
210 210
     rabl (0.2.8)
211  
-    rack (1.2.3)
  211
+    rack (1.2.5)
212 212
     rack-contrib (1.1.0)
213 213
       rack (>= 0.9.1)
214 214
     rack-mount (0.6.14)
@@ -233,19 +233,19 @@ GEM
233 233
       thor (~> 0.14.4)
234 234
     rake (0.8.7)
235 235
     rmagick (2.13.1)
236  
-    rspec (2.6.0)
237  
-      rspec-core (~> 2.6.0)
238  
-      rspec-expectations (~> 2.6.0)
239  
-      rspec-mocks (~> 2.6.0)
240  
-    rspec-core (2.6.4)
241  
-    rspec-expectations (2.6.0)
  236
+    rspec (2.8.0)
  237
+      rspec-core (~> 2.8.0)
  238
+      rspec-expectations (~> 2.8.0)
  239
+      rspec-mocks (~> 2.8.0)
  240
+    rspec-core (2.8.0)
  241
+    rspec-expectations (2.8.0)
242 242
       diff-lcs (~> 1.1.2)
243  
-    rspec-mocks (2.6.0)
244  
-    rspec-rails (2.6.1)
245  
-      actionpack (~> 3.0)
246  
-      activesupport (~> 3.0)
247  
-      railties (~> 3.0)
248  
-      rspec (~> 2.6.0)
  243
+    rspec-mocks (2.8.0)
  244
+    rspec-rails (2.8.1)
  245
+      actionpack (>= 3.0)
  246
+      activesupport (>= 3.0)
  247
+      railties (>= 3.0)
  248
+      rspec (~> 2.8.0)
249 249
     ruby-hmac (0.4.0)
250 250
     ruby-openid (2.1.8)
251 251
     rubyzip (0.9.4)
@@ -266,7 +266,7 @@ GEM
266 266
     treetop (1.4.9)
267 267
       polyglot (>= 0.3.1)
268 268
     trollop (1.16.2)
269  
-    tzinfo (0.3.27)
  269
+    tzinfo (0.3.31)
270 270
     validates_captcha (0.9.7)
271 271
       actionpack (>= 2.3.2)
272 272
       activerecord (>= 2.3.2)
167  lib/tasks/rspec.rake
... ...
@@ -1,167 +0,0 @@
1  
-gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9
2  
-rspec_plugin_dir = File.expand_path(File.dirname(__FILE__) + '/../../vendor/plugins/rspec')
3  
-$LOAD_PATH.unshift("#{rspec_plugin_dir}/lib") if File.exist?(rspec_plugin_dir)
4  
-
5  
-# Don't load rspec if running "rake gems:*"
6  
-unless ARGV.any? {|a| a =~ /^gems/}
7  
-
8  
-begin
9  
-  require 'spec/rake/spectask'
10  
-rescue MissingSourceFile
11  
-  module Spec
12  
-    module Rake
13  
-      class SpecTask
14  
-        def initialize(name)
15  
-          task name do
16  
-            # if rspec-rails is a configured gem, this will output helpful material and exit ...
17  
-            require File.expand_path(File.dirname(__FILE__) + "/../../config/environment")
18  
-
19  
-            # ... otherwise, do this:
20  
-            raise <<-MSG
21  
-
22  
-#{"*" * 80}
23  
-*  You are trying to run an rspec rake task defined in
24  
-*  #{__FILE__},
25  
-*  but rspec can not be found in vendor/gems, vendor/plugins or system gems.
26  
-#{"*" * 80}
27  
-MSG
28  
-          end
29  
-        end
30  
-      end
31  
-    end
32  
-  end
33  
-end
34  
-
35  
-Rake.application.instance_variable_get('@tasks').delete('default')
36  
-
37  
-spec_prereq = File.exist?(File.join(Rails.env, 'config', 'database.yml')) ? "db:test:prepare" : :noop
38  
-task :noop do
39  
-end
40  
-
41  
-task :default => :spec
42  
-task :stats => "spec:statsetup"
43  
-
44  
-desc "Run all specs in spec directory (excluding plugin specs)"
45  
-Spec::Rake::SpecTask.new(:spec => spec_prereq) do |t|
46  
-  t.spec_opts = ['--options', "\"#{Rails.env}/spec/spec.opts\""]
47  
-  t.spec_files = FileList['spec/**/*/*_spec.rb']
48  
-end
49  
-
50  
-namespace :spec do
51  
-  desc "Run all specs in spec directory with RCov (excluding plugin specs)"
52  
-  Spec::Rake::SpecTask.new(:rcov) do |t|
53  
-    t.spec_opts = ['--options', "\"#{Rails.env}/spec/spec.opts\""]
54  
-    t.spec_files = FileList['spec/**/*/*_spec.rb']
55  
-    t.rcov = true
56  
-    t.rcov_opts = lambda do
57  
-      IO.readlines("#{Rails.env}/spec/rcov.opts").map {|l| l.chomp.split " "}.flatten
58  
-    end
59  
-  end
60  
-
61  
-  desc "Print Specdoc for all specs (excluding plugin specs)"
62  
-  Spec::Rake::SpecTask.new(:doc) do |t|
63  
-    t.spec_opts = ["--format", "specdoc", "--dry-run"]
64  
-    t.spec_files = FileList['spec/**/*/*_spec.rb']
65  
-  end
66  
-
67  
-  desc "Print Specdoc for all plugin examples"
68  
-  Spec::Rake::SpecTask.new(:plugin_doc) do |t|
69  
-    t.spec_opts = ["--format", "specdoc", "--dry-run"]
70  
-    t.spec_files = FileList['vendor/plugins/**/spec/**/*/*_spec.rb'].exclude('vendor/plugins/rspec/*')
71  
-  end
72  
-
73  
-  [:models, :controllers, :views, :helpers, :lib].each do |sub|
74  
-    desc "Run the code examples in spec/#{sub}"
75  
-    Spec::Rake::SpecTask.new(sub => spec_prereq) do |t|
76  
-      t.spec_opts = ['--options', "\"#{Rails.env}/spec/spec.opts\""]
77  
-      t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
78  
-    end
79  
-  end
80  
-
81  
-  desc "Run the code examples in vendor/plugins (except RSpec's own)"
82  
-  Spec::Rake::SpecTask.new(:plugins => spec_prereq) do |t|
83  
-    t.spec_opts = ['--options', "\"#{Rails.env}/spec/spec.opts\""]
84  
-    t.spec_files = FileList['vendor/plugins/**/spec/**/*/*_spec.rb'].exclude('vendor/plugins/rspec/*').exclude("vendor/plugins/rspec-rails/*")
85  
-  end
86  
-
87  
-  namespace :plugins do
88  
-    desc "Runs the examples for rspec_on_rails"
89  
-    Spec::Rake::SpecTask.new(:rspec_on_rails) do |t|
90  
-      t.spec_opts = ['--options', "\"#{Rails.env}/spec/spec.opts\""]
91  
-      t.spec_files = FileList['vendor/plugins/rspec-rails/spec/**/*/*_spec.rb']
92  
-    end
93  
-  end
94  
-
95  
-  # Setup specs for stats
96  
-  task :statsetup do
97  
-    require 'code_statistics'
98  
-    ::STATS_DIRECTORIES << %w(Model\ specs spec/models) if File.exist?('spec/models')
99  
-    ::STATS_DIRECTORIES << %w(View\ specs spec/views) if File.exist?('spec/views')
100  
-    ::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers) if File.exist?('spec/controllers')
101  
-    ::STATS_DIRECTORIES << %w(Helper\ specs spec/helpers) if File.exist?('spec/helpers')
102  
-    ::STATS_DIRECTORIES << %w(Library\ specs spec/lib) if File.exist?('spec/lib')
103  
-    ::STATS_DIRECTORIES << %w(Routing\ specs spec/routing) if File.exist?('spec/routing')
104  
-    ::CodeStatistics::TEST_TYPES << "Model specs" if File.exist?('spec/models')
105  
-    ::CodeStatistics::TEST_TYPES << "View specs" if File.exist?('spec/views')
106  
-    ::CodeStatistics::TEST_TYPES << "Controller specs" if File.exist?('spec/controllers')
107  
-    ::CodeStatistics::TEST_TYPES << "Helper specs" if File.exist?('spec/helpers')
108  
-    ::CodeStatistics::TEST_TYPES << "Library specs" if File.exist?('spec/lib')
109  
-    ::CodeStatistics::TEST_TYPES << "Routing specs" if File.exist?('spec/routing')
110  
-  end
111  
-
112  
-  namespace :db do
113  
-    namespace :fixtures do
114  
-      desc "Load fixtures (from spec/fixtures) into the current environment's database.  Load specific fixtures using FIXTURES=x,y. Load from subdirectory in test/fixtures using FIXTURES_DIR=z."
115  
-      task :load => :environment do
116  
-        ActiveRecord::Base.establish_connection(Rails.env)
117  
-        base_dir = File.join(Rails.root, 'spec', 'fixtures')
118  
-        fixtures_dir = ENV['FIXTURES_DIR'] ? File.join(base_dir, ENV['FIXTURES_DIR']) : base_dir
119  
-        
120  
-        require 'active_record/fixtures'
121  
-        (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/).map {|f| File.join(fixtures_dir, f) } : Dir.glob(File.join(fixtures_dir, '*.{yml,csv}'))).each do |fixture_file|
122  
-          Fixtures.create_fixtures(File.dirname(fixture_file), File.basename(fixture_file, '.*'))
123  
-        end
124  
-      end
125  
-    end
126  
-  end
127  
-
128  
-  namespace :server do
129  
-    daemonized_server_pid = File.expand_path("#{Rails.env}/tmp/pids/spec_server.pid")
130  
-    
131  
-    desc "start spec_server."
132  
-    task :start do
133  
-      if File.exist?(daemonized_server_pid)
134  
-        $stderr.puts "spec_server is already running."
135  
-      else
136  
-        $stderr.puts %Q{Starting up spec_server ...}
137  
-        FileUtils.mkdir_p('tmp/pids') unless test ?d, 'tmp/pids'
138  
-        system("ruby", "script/spec_server", "--daemon", "--pid", daemonized_server_pid)
139  
-      end
140  
-    end
141  
-
142  
-    desc "stop spec_server."
143  
-    task :stop do
144  
-      unless File.exist?(daemonized_server_pid)
145  
-        $stderr.puts "No server running."
146  
-      else
147  
-        $stderr.puts "Shutting down spec_server ..."
148  
-        system("kill", "-s", "TERM", File.read(daemonized_server_pid).strip) && 
149  
-        File.delete(daemonized_server_pid)
150  
-      end
151  
-    end
152  
-
153  
-    desc "restart spec_server."
154  
-    task :restart => [:stop, :start]
155  
-    
156  
-    desc "check if spec server is running"
157  
-    task :status do
158  
-      if File.exist?(daemonized_server_pid)
159  
-        $stderr.puts %Q{spec_server is running (PID: #{File.read(daemonized_server_pid).gsub("\n","")})}
160  
-      else
161  
-        $stderr.puts "No server running."
162  
-      end
163  
-    end
164  
-  end
165  
-end
166  
-
167  
-end
11  spec/controllers/index_controller_spec.rb
... ...
@@ -0,0 +1,11 @@
  1
+require 'spec_helper'
  2
+
  3
+describe IndexController do
  4
+  render_views
  5
+  describe 'index' do
  6
+    it 'should load' do
  7
+      get :index
  8
+      response.should be_success
  9
+    end
  10
+  end
  11
+end
31  spec/models/article_spec.rb
... ...
@@ -1,31 +0,0 @@
1  
-require File.dirname(__FILE__) + '/../spec_helper'
2  
-
3  
-describe Article do
4  
-  before(:each) do
5  
-    @valid_attributes = {
6  
-
7  
-    }
8  
-  end
9  
-
10  
-  it "should create a new instance given valid attributes" do
11  
-    Article.create!(@valid_attributes)
12  
-  end
13  
-
14  
-  it "should return articles for a given tag" do
15  
-    finreg1 = Article.find_by_title("Will the Agriculture Committee Hand Wall Street a Big Win on Derivatives?")
16  
-    
17  
-    articles = Article.tagged_with("Financial Reform")
18  
-    
19  
-    articles.should include(finreg1)
20  
-  end
21  
-
22  
-  it "should return articles for a given tag regardless of case" do
23  
-    finreg1 = Article.find_by_title("Will the Agriculture Committee Hand Wall Street a Big Win on Derivatives?")
24  
-    finreg2 = Article.find_by_title("House Dems take on Wall Street Bonuses")
25  
-    
26  
-    articles = Article.tagged_with("Financial Reform")
27  
-    
28  
-    articles.should include(finreg1)
29  
-    articles.should include(finreg2)
30  
-  end
31  
-end
2  spec/rcov.opts
... ...
@@ -1,2 +0,0 @@
1  
---exclude "spec/*,gems/*" 
2  
---rails
4  spec/spec.opts
... ...
@@ -1,4 +0,0 @@
1  
---colour
2  
---format progress
3  
---loadby mtime
4  
---reverse
61  spec/spec_helper.rb
... ...
@@ -1,47 +1,32 @@
1  
-# This file is copied to ~/spec when you run 'ruby script/generate rspec'
2  
-# from the project root directory.
  1
+# This file is copied to spec/ when you run 'rails generate rspec:install'
3 2
 ENV["RAILS_ENV"] ||= 'test'
4  
-require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT)
5  
-require 'spec/autorun'
6  
-require 'spec/rails'
  3
+require File.expand_path("../../config/environment", __FILE__)
  4
+require 'rspec/rails'
  5
+require 'rspec/autorun'
7 6
 
8  
-Spec::Runner.configure do |config|
9  
-  # If you're not using ActiveRecord you should remove these
10  
-  # lines, delete config/database.yml and disable :active_record
11  
-  # in your config/boot.rb
12  
-  config.use_transactional_fixtures = false
13  
-  config.use_instantiated_fixtures  = false
14  
-  config.fixture_path = RAILS_ROOT + '/features/fixtures/'
  7
+# Requires supporting ruby files with custom matchers and macros, etc,
  8
+# in spec/support/ and its subdirectories.
  9
+Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
15 10
 
16  
-  # == Fixtures
  11
+RSpec.configure do |config|
  12
+  # ## Mock Framework
17 13
   #
18  
-  # You can declare fixtures for each example_group like this:
19  
-  #   describe "...." do
20  
-  #     fixtures :table_a, :table_b
21  
-  #
22  
-  # Alternatively, if you prefer to declare them only once, you can
23  
-  # do so right here. Just uncomment the next line and replace the fixture
24  
-  # names with your fixtures.
25  
-  #
26  
-  # config.global_fixtures = :table_a, :table_b
27  
-  #
28  
-  # If you declare global fixtures, be aware that they will be declared
29  
-  # for all of your examples, even those that don't use them.
30  
-  #
31  
-  # You can also declare which fixtures to use (for example fixtures for test/fixtures):
32  
-  #
33  
-  #config.fixture_path = RAILS_ROOT + '/features/fixtures/'
34  
-  #
35  
-  # == Mock Framework
36  
-  #
37  
-  # RSpec uses it's own mocking framework by default. If you prefer to
38  
-  # use mocha, flexmock or RR, uncomment the appropriate line:
  14
+  # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
39 15
   #
40 16
   # config.mock_with :mocha
41 17
   # config.mock_with :flexmock
42 18
   # config.mock_with :rr
43  
-  #
44  
-  # == Notes
45  
-  # 
46  
-  # For more information take a look at Spec::Runner::Configuration and Spec::Runner
  19
+
  20
+  # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
  21
+  config.fixture_path = "#{::Rails.root}/spec/fixtures"
  22
+
  23
+  # If you're not using ActiveRecord, or you'd prefer not to run each of your
  24
+  # examples within a transaction, remove the following line or assign false
  25
+  # instead of true.
  26
+  config.use_transactional_fixtures = true
  27
+
  28
+  # If true, the base class of anonymous controllers will be inferred
  29
+  # automatically. This will be the default behavior in future versions of
  30
+  # rspec-rails.
  31
+  config.infer_base_class_for_anonymous_controllers = false
47 32
 end
11  spec/spec_suite.rb
... ...
@@ -1,11 +0,0 @@
1  
-class SpecSuite
2  
-  def run
3  
-    Dir["#{File.dirname(__FILE__)}/**/*_spec.rb"].each do |file|
4  
-      require file
5  
-    end
6  
-  end
7  
-end
8  
-
9  
-if $0 == __FILE__
10  
-  SpecSuite.new.run
11  
-end

0 notes on commit fc51f15

Please sign in to comment.
Something went wrong with that request. Please try again.