mspec 1.5.15 → 1.5.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile CHANGED
@@ -18,7 +18,7 @@ spec = Gem::Specification.new do |s|
18
18
 
19
19
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
20
20
  s.authors = ["Brian Ford"]
21
- s.date = %q{2010-02-04}
21
+ s.date = %q{2010-02-08}
22
22
  s.email = %q{bford@engineyard.com}
23
23
  s.has_rdoc = true
24
24
  s.extra_rdoc_files = %w[ README LICENSE ]
@@ -7,6 +7,7 @@ require 'mspec/helpers/enumerator_class'
7
7
  require 'mspec/helpers/environment'
8
8
  require 'mspec/helpers/fixture'
9
9
  require 'mspec/helpers/flunk'
10
+ require 'mspec/helpers/fmode'
10
11
  require 'mspec/helpers/fs'
11
12
  require 'mspec/helpers/hash'
12
13
  require 'mspec/helpers/infinity'
@@ -15,6 +15,7 @@ class Object
15
15
  def fixture(dir, *args)
16
16
  path = File.dirname(dir)
17
17
  path = path[0..-7] if path[-7..-1] == "/shared"
18
- File.expand_path(File.join(path, "fixtures", args))
18
+ dir = path[-9..-1] == "/fixtures" ? "" : "fixtures"
19
+ File.expand_path(File.join(path, dir, args))
19
20
  end
20
21
  end
@@ -0,0 +1,15 @@
1
+ require 'mspec/guards/feature'
2
+
3
+ class Object
4
+ # This helper simplifies passing file access modes regardless of
5
+ # whether the :encoding feature is enabled. Only the access specifier
6
+ # itself will be returned if :encoding is not enabled. Otherwise,
7
+ # the full mode string will be returned (i.e. the helper is a no-op).
8
+ def fmode(mode)
9
+ if FeatureGuard.enabled? :encoding
10
+ mode
11
+ else
12
+ mode.split(':').first
13
+ end
14
+ end
15
+ end
@@ -14,6 +14,7 @@ require 'mspec/matchers/equal_element'
14
14
  require 'mspec/matchers/equal_utf16'
15
15
  require 'mspec/matchers/have_constant'
16
16
  require 'mspec/matchers/have_class_variable'
17
+ require 'mspec/matchers/have_data'
17
18
  require 'mspec/matchers/have_instance_method'
18
19
  require 'mspec/matchers/have_instance_variable'
19
20
  require 'mspec/matchers/have_method'
@@ -0,0 +1,48 @@
1
+ require 'mspec/guards/feature'
2
+ require 'mspec/helpers/fmode'
3
+
4
+ class HaveDataMatcher
5
+ def initialize(data)
6
+ @data = data
7
+ end
8
+
9
+ def matches?(name)
10
+ @name = name
11
+
12
+ if FeatureGuard.enabled? :encoding
13
+ size = @data.bytesize
14
+ else
15
+ size = @data.size
16
+ end
17
+
18
+ File.open @name, fmode("rb:binary") do |f|
19
+ return f.read(size) == @data
20
+ end
21
+ end
22
+
23
+ def failure_message
24
+ ["Expected #{@name}",
25
+ "to have data #{@data.pretty_inspect}"]
26
+ end
27
+
28
+ def negative_failure_message
29
+ ["Expected #{@name}",
30
+ "not to have data #{@data.pretty_inspect}"]
31
+ end
32
+ end
33
+
34
+ class Object
35
+ # Opens a file specified by the string the matcher is called on
36
+ # and compares the +data+ passed to the matcher with the contents
37
+ # of the file. Expects to match the first N bytes of the file
38
+ # with +data+. For example, suppose @name is the name of a file:
39
+ #
40
+ # @name.should have_data("123")
41
+ #
42
+ # passes if the file @name has "123" as the first 3 bytes. The
43
+ # file can contain more bytes than +data+. The extra bytes do not
44
+ # affect the result.
45
+ def have_data(data)
46
+ HaveDataMatcher.new(data)
47
+ end
48
+ end
@@ -1,5 +1,5 @@
1
1
  require 'mspec/utils/version'
2
2
 
3
3
  module MSpec
4
- VERSION = SpecVersion.new "1.5.15"
4
+ VERSION = SpecVersion.new "1.5.16"
5
5
  end
@@ -15,4 +15,9 @@ describe Object, "#fixture" do
15
15
  name = fixture("some/path/shared/file.rb", "dir", "file.txt")
16
16
  name.should == "#{@dir}/some/path/fixtures/dir/file.txt"
17
17
  end
18
+
19
+ it "does not append '/fixtures' if it is the suffix of the directory string" do
20
+ name = fixture("some/path/fixtures/file.rb", "dir", "file.txt")
21
+ name.should == "#{@dir}/some/path/fixtures/dir/file.txt"
22
+ end
18
23
  end
@@ -0,0 +1,14 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'mspec/helpers/fmode'
3
+
4
+ describe Object, "#fmode" do
5
+ it "returns the argument unmodified if :encoding feature is enabled" do
6
+ FeatureGuard.should_receive(:enabled?).with(:encoding).and_return(true)
7
+ fmode("rb:binary:utf-8").should == "rb:binary:utf-8"
8
+ end
9
+
10
+ it "returns only the file access mode if :encoding feature is not enabled" do
11
+ FeatureGuard.should_receive(:enabled?).with(:encoding).and_return(false)
12
+ fmode("rb:binary:utf-8").should == "rb"
13
+ end
14
+ end
@@ -0,0 +1,51 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'mspec/expectations/expectations'
3
+ require 'mspec/matchers/have_data'
4
+ require 'mspec/helpers/tmp'
5
+ require 'mspec/helpers/fs'
6
+
7
+ describe HaveDataMatcher do
8
+ before :each do
9
+ @name = tmp "have_data_matcher"
10
+ touch(@name) { |f| f.puts "123abc" }
11
+ end
12
+
13
+ after :each do
14
+ rm_r @name
15
+ end
16
+
17
+ it "raises an IOError if the named file does not exist" do
18
+ lambda do
19
+ HaveDataMatcher.new("123").matches?("no_file.txt")
20
+ end.should raise_error(Errno::ENOENT)
21
+ end
22
+
23
+ it "matches when the named file begins with the same bytes as data" do
24
+ HaveDataMatcher.new("123a").matches?(@name).should be_true
25
+ end
26
+
27
+ it "does not match when the named file begins with fewer bytes than data" do
28
+ HaveDataMatcher.new("123abcPQR").matches?(@name).should be_false
29
+
30
+ end
31
+
32
+ it "does not match when the named file begins with different bytes than data" do
33
+ HaveDataMatcher.new("abc1").matches?(@name).should be_false
34
+ end
35
+
36
+ it "provides a useful failure message" do
37
+ matcher = HaveDataMatcher.new("abc1")
38
+ matcher.matches?(@name)
39
+ matcher.failure_message.should == [
40
+ "Expected #{@name}", "to have data \"abc1\"\n"
41
+ ]
42
+ end
43
+
44
+ it "provides a useful negative failure message" do
45
+ matcher = HaveDataMatcher.new("123abc")
46
+ matcher.matches?(@name)
47
+ matcher.negative_failure_message.should == [
48
+ "Expected #{@name}", "not to have data \"123abc\"\n"
49
+ ]
50
+ end
51
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.15
4
+ version: 1.5.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Ford
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-04 00:00:00 -08:00
12
+ date: 2010-02-08 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -62,6 +62,7 @@ files:
62
62
  - lib/mspec/helpers/environment.rb
63
63
  - lib/mspec/helpers/fixture.rb
64
64
  - lib/mspec/helpers/flunk.rb
65
+ - lib/mspec/helpers/fmode.rb
65
66
  - lib/mspec/helpers/fs.rb
66
67
  - lib/mspec/helpers/hash.rb
67
68
  - lib/mspec/helpers/infinity.rb
@@ -90,6 +91,7 @@ files:
90
91
  - lib/mspec/matchers/equal_utf16.rb
91
92
  - lib/mspec/matchers/have_class_variable.rb
92
93
  - lib/mspec/matchers/have_constant.rb
94
+ - lib/mspec/matchers/have_data.rb
93
95
  - lib/mspec/matchers/have_instance_method.rb
94
96
  - lib/mspec/matchers/have_instance_variable.rb
95
97
  - lib/mspec/matchers/have_method.rb
@@ -192,6 +194,7 @@ files:
192
194
  - spec/helpers/environment_spec.rb
193
195
  - spec/helpers/fixture_spec.rb
194
196
  - spec/helpers/flunk_spec.rb
197
+ - spec/helpers/fmode_spec.rb
195
198
  - spec/helpers/fs_spec.rb
196
199
  - spec/helpers/hash_spec.rb
197
200
  - spec/helpers/infinity_spec.rb
@@ -218,6 +221,7 @@ files:
218
221
  - spec/matchers/equal_utf16_spec.rb
219
222
  - spec/matchers/have_class_variable_spec.rb
220
223
  - spec/matchers/have_constant_spec.rb
224
+ - spec/matchers/have_data_spec.rb
221
225
  - spec/matchers/have_instance_method_spec.rb
222
226
  - spec/matchers/have_instance_variable_spec.rb
223
227
  - spec/matchers/have_method_spec.rb