rspec-core 2.0.0.a4 → 2.0.0.a5

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -6,3 +6,4 @@ rdoc
6
6
  pkg
7
7
  tmp
8
8
  tags
9
+ rerun.txt
@@ -5,7 +5,6 @@
5
5
  * from command line
6
6
  * in rake task definitions
7
7
  * formatters
8
- * Ensure context works everywhere describe does
9
8
  * For self testing
10
9
  ** shared example groups should not be merged into the real 'world'
11
10
  * make sure all behaviour refs are now examplegroup
@@ -1,3 +1,7 @@
1
- default: features -r features -t ~@wip
2
- wip: features -r features -t @wip
3
- all: features -r features
1
+ <%
2
+ rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
3
+ rerun_opts = rerun.to_s.strip.empty? ? "--format progress features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
4
+ std_opts = "#{rerun_opts} --require features --format rerun --out rerun.txt --strict --tags ~@wip"
5
+ %>
6
+ default: <%= std_opts %>
7
+ wip: --tags @wip:3 --wip features
@@ -0,0 +1,76 @@
1
+ Feature: spec/spec.opts
2
+
3
+ For backwards compatibility with rspec-1, you can write command
4
+ line options in a spec/spec.opts file and it will be loaded
5
+ automatically.
6
+
7
+ Options declared in spec/spec.opts will override configuration
8
+ set up in Rspec::Core.configure blocks.
9
+
10
+ Background:
11
+ Given a directory named "spec"
12
+
13
+ Scenario: color set in Rspec::Core.configure
14
+ Given a file named "spec/spec_helper.rb" with:
15
+ """
16
+ Rspec::Core.configure do |c|
17
+ c.color_enabled = true
18
+ end
19
+ """
20
+ And a file named "spec/example_spec.rb" with:
21
+ """
22
+ require "spec_helper"
23
+ describe "color_enabled" do
24
+ context "when set with Rspec::Core.configure" do
25
+ it "is true" do
26
+ Rspec::Core.configuration.color_enabled?.should be_true
27
+ end
28
+ end
29
+ end
30
+ """
31
+ When I run "rspec spec/example_spec.rb"
32
+ Then the stdout should match "1 example, 0 failures"
33
+
34
+ Scenario: color set in spec/spec.opts
35
+ Given a file named "spec/spec.opts" with:
36
+ """
37
+ --color
38
+ """
39
+ And a file named "spec/example_spec.rb" with:
40
+ """
41
+ describe "color_enabled" do
42
+ context "when set with Rspec::Core.configure" do
43
+ it "is true" do
44
+ Rspec::Core.configuration.color_enabled?.should be_true
45
+ end
46
+ end
47
+ end
48
+ """
49
+ When I run "rspec spec/example_spec.rb"
50
+ Then the stdout should match "1 example, 0 failures"
51
+
52
+ Scenario: formatter set in both (spec.opts wins)
53
+ Given a file named "spec/spec.opts" with:
54
+ """
55
+ --formatter documentation
56
+ """
57
+
58
+ And a file named "spec/spec_helper.rb" with:
59
+ """
60
+ Rspec::Core.configure do |c|
61
+ c.formatter = 'pretty'
62
+ end
63
+ """
64
+ And a file named "spec/example_spec.rb" with:
65
+ """
66
+ describe "formatter" do
67
+ context "when set with Rspec::Core.configure and in spec.opts" do
68
+ it "takes the value set in spec.opts" do
69
+ Rspec::Core.configuration.formatter.should be_an(Rspec::Core::Formatters::DocumentationFormatter)
70
+ end
71
+ end
72
+ end
73
+ """
74
+ When I run "rspec spec/example_spec.rb"
75
+ Then the stdout should match "1 example, 0 failures"
76
+
@@ -1,12 +1,16 @@
1
- Given %r{^a file named "([^"]+)" with:$} do |file_name, code|
1
+ Given /^a directory named "([^"]+)"$/ do |dirname|
2
+ create_dir(dirname)
3
+ end
4
+
5
+ Given /^a file named "([^"]+)" with:$/ do |file_name, code|
2
6
  create_file(file_name, code)
3
7
  end
4
8
 
5
- When %r{^I run "r?spec ([^"]+)"$} do |file_and_args|
9
+ When /^I run "r?spec ([^"]+)"$/ do |file_and_args|
6
10
  spec(file_and_args)
7
11
  end
8
12
 
9
- When %r{^I run "ruby ([^"]+)"$} do |file_and_args|
13
+ When /^I run "ruby ([^"]+)"$/ do |file_and_args|
10
14
  ruby(file_and_args)
11
15
  end
12
16
 
@@ -26,6 +26,10 @@ class RspecWorld
26
26
  ruby("#{spec_command} #{args}")
27
27
  end
28
28
 
29
+ def create_dir(dirname)
30
+ FileUtils.mkdir_p File.join(working_dir, dirname)
31
+ end
32
+
29
33
  def create_file(file_name, contents)
30
34
  file_path = File.join(working_dir, file_name)
31
35
  File.open(file_path, "w") { |f| f << contents }
@@ -1,14 +1,33 @@
1
1
  require 'rspec/expectations'
2
2
 
3
3
  Rspec::Matchers.define :smart_match do |expected|
4
+ def regexp?
5
+ /^\/.*\/?$/
6
+ end
7
+
8
+ def quoted?
9
+ /^".*"$/
10
+ end
11
+
4
12
  match do |actual|
5
13
  case expected
6
- when /^\/.*\/?$/
14
+ when regexp?
7
15
  actual =~ eval(expected)
8
- when /^".*"$/
16
+ when quoted?
9
17
  actual.index(eval(expected))
10
- else
11
- false
18
+ else # multi-line string
19
+ actual.index(expected)
12
20
  end
13
21
  end
22
+
23
+ failure_message_for_should do |actual|
24
+ <<-MESSAGE
25
+ #{'*'*50}
26
+ got:
27
+ #{'*'*30}
28
+ #{actual}
29
+ #{'*'*50}
30
+ MESSAGE
31
+ end
32
+
14
33
  end
@@ -5,6 +5,7 @@ module Rspec
5
5
  module Core
6
6
 
7
7
  class CommandLineOptions
8
+ DEFAULT_OPTIONS_FILE = 'spec/spec.opts'
8
9
 
9
10
  attr_reader :args, :options
10
11
 
@@ -38,6 +39,10 @@ module Rspec
38
39
  options[:full_description] = /#{o}/
39
40
  end
40
41
 
42
+ opts.on('-o', '--options [PATH]', 'Read configuration options from a file path. (Defaults to spec/spec.opts)') do |o|
43
+ options[:options_file] = o || DEFAULT_OPTIONS_FILE
44
+ end
45
+
41
46
  opts.on('-p', '--profile', 'Enable profiling of examples with output of the top 10 slowest examples') do |o|
42
47
  options[:profile_examples] = o
43
48
  end
@@ -56,11 +61,26 @@ module Rspec
56
61
  end
57
62
 
58
63
  def apply(config)
64
+ # 1) option file, cli options, rspec core configure
65
+ # TODO: Add options_file to configuration
66
+ # TODO: Store command line options for reference
67
+ options_file = options.delete(:options_file) || DEFAULT_OPTIONS_FILE
68
+ merged_options = parse_spec_file_contents(options_file).merge!(options)
69
+ options.replace merged_options
70
+
59
71
  options.each do |key, value|
60
72
  config.send("#{key}=", value)
61
73
  end
62
74
  end
63
75
 
76
+ private
77
+
78
+ def parse_spec_file_contents(options_file)
79
+ return {} unless File.exist?(options_file)
80
+ spec_file_contents = File.readlines(options_file).map {|l| l.split}.flatten
81
+ self.class.new(spec_file_contents).parse.options
82
+ end
83
+
64
84
  end
65
85
 
66
86
  end
@@ -5,7 +5,7 @@ module Rspec # :nodoc:
5
5
  MAJOR = 2
6
6
  MINOR = 0
7
7
  TINY = 0
8
- PRE = 'a4'
8
+ PRE = 'a5'
9
9
 
10
10
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
11
11
 
@@ -1,15 +1,15 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rspec-core}
8
- s.version = "2.0.0.a4"
8
+ s.version = "2.0.0.a5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Chad Humphries", "David Chelimsky"]
12
- s.date = %q{2010-02-04}
12
+ s.date = %q{2010-02-07}
13
13
  s.default_executable = %q{rspec}
14
14
  s.description = %q{Rspec runner and example group classes}
15
15
  s.email = %q{dchelimsky@gmail.com;chad.humphries@gmail.com}
@@ -96,6 +96,7 @@ Gem::Specification.new do |s|
96
96
  "features/command_line/example_name_option.feature",
97
97
  "features/command_line/line_number_appended_to_path.feature",
98
98
  "features/command_line/line_number_option.feature",
99
+ "features/configuration/spec_opts.feature",
99
100
  "features/example_groups/describe_aliases.feature",
100
101
  "features/example_groups/nested_groups.feature",
101
102
  "features/expectations/customized_message.feature",
@@ -175,7 +176,7 @@ Gem::Specification.new do |s|
175
176
  s.require_paths = ["lib"]
176
177
  s.rubyforge_project = %q{rspec}
177
178
  s.rubygems_version = %q{1.3.5}
178
- s.summary = %q{rspec-core 2.0.0.a4}
179
+ s.summary = %q{rspec-core 2.0.0.a5}
179
180
  s.test_files = [
180
181
  "spec/rspec/core/command_line_options_spec.rb",
181
182
  "spec/rspec/core/configuration_spec.rb",
@@ -208,17 +209,17 @@ Gem::Specification.new do |s|
208
209
  s.specification_version = 3
209
210
 
210
211
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
211
- s.add_development_dependency(%q<rspec-expectations>, [">= 2.0.0.a4"])
212
- s.add_development_dependency(%q<rspec-mocks>, [">= 2.0.0.a4"])
212
+ s.add_development_dependency(%q<rspec-expectations>, [">= 2.0.0.a5"])
213
+ s.add_development_dependency(%q<rspec-mocks>, [">= 2.0.0.a5"])
213
214
  s.add_development_dependency(%q<cucumber>, [">= 0.5.3"])
214
215
  else
215
- s.add_dependency(%q<rspec-expectations>, [">= 2.0.0.a4"])
216
- s.add_dependency(%q<rspec-mocks>, [">= 2.0.0.a4"])
216
+ s.add_dependency(%q<rspec-expectations>, [">= 2.0.0.a5"])
217
+ s.add_dependency(%q<rspec-mocks>, [">= 2.0.0.a5"])
217
218
  s.add_dependency(%q<cucumber>, [">= 0.5.3"])
218
219
  end
219
220
  else
220
- s.add_dependency(%q<rspec-expectations>, [">= 2.0.0.a4"])
221
- s.add_dependency(%q<rspec-mocks>, [">= 2.0.0.a4"])
221
+ s.add_dependency(%q<rspec-expectations>, [">= 2.0.0.a5"])
222
+ s.add_dependency(%q<rspec-mocks>, [">= 2.0.0.a5"])
222
223
  s.add_dependency(%q<cucumber>, [">= 0.5.3"])
223
224
  end
224
225
  end
@@ -1,4 +1,5 @@
1
1
  require 'spec_helper'
2
+ require 'ostruct'
2
3
 
3
4
  describe Rspec::Core::CommandLineOptions do
4
5
 
@@ -7,7 +8,6 @@ describe Rspec::Core::CommandLineOptions do
7
8
  end
8
9
 
9
10
  describe 'color_enabled' do
10
-
11
11
  example "-c, --colour, or --color should be parsed as true" do
12
12
  options_from_args('-c').should include(:color_enabled => true)
13
13
  options_from_args('--color').should include(:color_enabled => true)
@@ -17,11 +17,9 @@ describe Rspec::Core::CommandLineOptions do
17
17
  example "--no-color should be parsed as false" do
18
18
  options_from_args('--no-color').should include(:color_enabled => false)
19
19
  end
20
-
21
20
  end
22
21
 
23
22
  describe 'formatter' do
24
-
25
23
  example '-f or --formatter with no arguments should be parsed as nil' do
26
24
  options_from_args('--formatter').should include(:formatter => nil)
27
25
  end
@@ -31,16 +29,13 @@ describe Rspec::Core::CommandLineOptions do
31
29
  options_from_args('-f', 'd').should include(:formatter => 'd')
32
30
  options_from_args('-fd').should include(:formatter => 'd')
33
31
  end
34
-
35
32
  end
36
33
 
37
34
  describe 'profile_examples' do
38
-
39
35
  example "-p or --profile should be parsed as true" do
40
36
  options_from_args('-p').should include(:profile_examples => true)
41
37
  options_from_args('--profile').should include(:profile_examples => true)
42
38
  end
43
-
44
39
  end
45
40
 
46
41
  describe 'line_number' do
@@ -57,8 +52,54 @@ describe Rspec::Core::CommandLineOptions do
57
52
  end
58
53
  end
59
54
 
60
- describe "files_or_directories_to_run" do
55
+ describe "options" do
56
+ it "is parsed from --options or -o" do
57
+ options_from_args('--options', 'spec/spec.opts').should include(:options_file => "spec/spec.opts")
58
+ options_from_args('-o', 'foo/spec.opts').should include(:options_file => "foo/spec.opts")
59
+ end
60
+
61
+ it "defaults to spec/spec.opts when you don't give it a file path" do
62
+ options_from_args('-o').should include(:options_file => "spec/spec.opts")
63
+ options_from_args('--options').should include(:options_file => "spec/spec.opts")
64
+ end
61
65
 
66
+ it "loads automatically" do
67
+ cli_options = Rspec::Core::CommandLineOptions.new([]).parse
68
+ File.stub(:exist?) { true }
69
+ File.stub(:readlines) { ["--formatter", "doc"] }
70
+ config = OpenStruct.new
71
+ cli_options.apply(config)
72
+ config.formatter.should == 'doc'
73
+ end
74
+
75
+ it "allows options on one line" do
76
+ cli_options = Rspec::Core::CommandLineOptions.new([]).parse
77
+ File.stub(:exist?) { true }
78
+ File.stub(:readlines) { ["--formatter doc"] }
79
+ config = OpenStruct.new
80
+ cli_options.apply(config)
81
+ config.formatter.should == 'doc'
82
+ end
83
+
84
+ it "merges options from the CLI and file options gracefully" do
85
+ cli_options = Rspec::Core::CommandLineOptions.new(['--formatter', 'progress', '--options', 'spec/spec.opts']).parse
86
+ cli_options.stub!(:parse_spec_file_contents).and_return(:full_backtrace => true)
87
+ config = OpenStruct.new
88
+ cli_options.apply(config)
89
+ config.full_backtrace.should == true
90
+ config.formatter.should == 'progress'
91
+ end
92
+
93
+ it "CLI options trump file options" do
94
+ cli_options = Rspec::Core::CommandLineOptions.new(['--formatter', 'progress', '--options', 'spec/spec.opts']).parse
95
+ cli_options.stub!(:parse_spec_file_contents).and_return(:formatter => 'documentation')
96
+ config = OpenStruct.new
97
+ cli_options.apply(config)
98
+ config.formatter.should == 'progress'
99
+ end
100
+ end
101
+
102
+ describe "files_or_directories_to_run" do
62
103
  it "parses files from '-c file.rb dir/file.rb'" do
63
104
  options_from_args("-c", "file.rb", "dir/file.rb").should include(:files_or_directories_to_run => ["file.rb", "dir/file.rb"])
64
105
  end
@@ -56,13 +56,13 @@ ensure
56
56
  Rspec::Core.configuration.instance_variable_set(:@formatter, original_formatter)
57
57
  end
58
58
 
59
- def not_in_editor?
60
- !(ENV.has_key?('TM_MODE') || ENV.has_key?('EMACS') || ENV.has_key?('VIM'))
59
+ def in_editor?
60
+ ENV.has_key?('TM_MODE') || ENV.has_key?('EMACS') || ENV.has_key?('VIM')
61
61
  end
62
62
 
63
63
  Rspec::Core.configure do |c|
64
64
  c.mock_framework = :rspec
65
65
  c.filter_run :focused => true
66
66
  c.run_all_when_everything_filtered = true
67
- c.color_enabled = not_in_editor?
67
+ c.color_enabled = !in_editor?
68
68
  end
@@ -20,7 +20,7 @@ end
20
20
 
21
21
  def run(files_to_run)
22
22
  puts("Running: #{files_to_run}")
23
- system("clear;bin/rspec -cfn #{files_to_run}")
23
+ system("clear;rspec -cfs #{files_to_run}")
24
24
  no_int_for_you
25
25
  end
26
26
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.a4
4
+ version: 2.0.0.a5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chad Humphries
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2010-02-04 00:00:00 -06:00
13
+ date: 2010-02-07 00:00:00 -04:00
14
14
  default_executable: rspec
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -21,7 +21,7 @@ dependencies:
21
21
  requirements:
22
22
  - - ">="
23
23
  - !ruby/object:Gem::Version
24
- version: 2.0.0.a4
24
+ version: 2.0.0.a5
25
25
  version:
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: rspec-mocks
@@ -31,7 +31,7 @@ dependencies:
31
31
  requirements:
32
32
  - - ">="
33
33
  - !ruby/object:Gem::Version
34
- version: 2.0.0.a4
34
+ version: 2.0.0.a5
35
35
  version:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: cucumber
@@ -130,6 +130,7 @@ files:
130
130
  - features/command_line/example_name_option.feature
131
131
  - features/command_line/line_number_appended_to_path.feature
132
132
  - features/command_line/line_number_option.feature
133
+ - features/configuration/spec_opts.feature
133
134
  - features/example_groups/describe_aliases.feature
134
135
  - features/example_groups/nested_groups.feature
135
136
  - features/expectations/customized_message.feature
@@ -230,7 +231,7 @@ rubyforge_project: rspec
230
231
  rubygems_version: 1.3.5
231
232
  signing_key:
232
233
  specification_version: 3
233
- summary: rspec-core 2.0.0.a4
234
+ summary: rspec-core 2.0.0.a5
234
235
  test_files:
235
236
  - spec/rspec/core/command_line_options_spec.rb
236
237
  - spec/rspec/core/configuration_spec.rb