bc-rspec-matchers 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012 Vasco
1
+ Copyright (c) 2012 Byclosure, Lda.
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,24 +1,42 @@
1
1
  # Bc::Rspec::Matchers
2
2
 
3
- TODO: Write a gem description
3
+ This projects aims to be an open source effort to collect all the RSpec custom matchers & macros used across Byclosure projects.
4
4
 
5
5
  ## Installation
6
6
 
7
7
  Add this line to your application's Gemfile:
8
8
 
9
- gem 'bc-rspec-matchers'
9
+ gem 'bc-rspec-matchers', "~> 0.0.3"
10
10
 
11
11
  And then execute:
12
12
 
13
+ $ bundle install
14
+
15
+ Go to your RSpec configuration files and add:
16
+
17
+ RSpec.configure do |c|
18
+ c.include Bc::RSpec::Matchers
19
+ end
20
+
21
+ ## Development & Improvment of bc-rspec-matchers
22
+
13
23
  $ bundle
14
24
 
15
- Or install it yourself as:
16
25
 
17
- $ gem install bc-rspec-matchers
26
+ To run specs in autotest enable just run: `bundle exec autotest`.
27
+
28
+ To run specs, just run: `bundle exec rake spec`
18
29
 
19
- ## Usage
20
30
 
21
- TODO: Write usage instructions here
31
+ ## Add new gem dependencies
32
+
33
+ *Atention:* Do not use Gemfile for that, Gemfile will automatically be created for you.
34
+
35
+ Steps:
36
+
37
+ 1. Go to bc-rspec-matchers.gem
38
+ 2. See and use the `gem.add_development_dependency` (that works the same way as Gemfile depencies)
39
+ 3. run `bundle`
22
40
 
23
41
  ## Contributing
24
42
 
@@ -34,13 +52,8 @@ See: http://railscasts.com/episodes/245-new-gem-with-bundler?view=asciicast
34
52
 
35
53
  ### Update & Release
36
54
 
37
- Run `bundle exec rake release`
38
-
39
- or
40
-
41
- 1. Update `lib/bc-rspec-matchers/version.rb` version.rb
42
- 2. gem build
43
- 3. gem push
55
+ 1. Update gem version: `lib/bc-rspec-matchers/version.rb`
56
+ 2. Run `bundle exec rake release`
44
57
 
45
58
  # Relevant blog posts
46
59
  * http://eggsonbread.com/2010/03/28/my-rspec-best-practices-and-tips/
@@ -2,3 +2,4 @@ $:.unshift(File.dirname(__FILE__))
2
2
 
3
3
  require "bc-rspec-matchers/version"
4
4
  require "bc-rspec-matchers/data_structure"
5
+ require "bc-rspec-matchers/content_type"
@@ -0,0 +1,43 @@
1
+ module Bc
2
+ module RSpec
3
+ module Matchers
4
+ class ContentType
5
+ @@sym_to_regexp = {
6
+ :json => /application\/json\s*;\s*charset=utf-8/
7
+ }
8
+
9
+ attr_reader :symbol, :header
10
+ def initialize(content_type_symbol)
11
+ @symbol = content_type_symbol.to_sym
12
+ end
13
+
14
+ def matches?(actual)
15
+ @header = actual
16
+ content_type(actual) =~ sym_to_regexp(symbol)
17
+ end
18
+
19
+ def failure_message_for_should
20
+ "Content-Type was #{content_type(header).inspect}, expecting type #{symbol} (#{sym_to_regexp(symbol).inspect})"
21
+ end
22
+
23
+ def failure_message_for_should_not
24
+ "Content-Type (#{content_type(header).inspect}) should not match #{symbol} (#{sym_to_regexp(symbol).inspect})"
25
+ end
26
+
27
+ def description
28
+ "have Content-Type of type #{symbol}"
29
+ end
30
+
31
+ private
32
+ def content_type(header)
33
+ raise(ArgumentError.new("Expecting #{header.inspect} to be an header (type Hash)")) unless header.is_a?(Hash)
34
+ header["Content-Type"]
35
+ end
36
+
37
+ def sym_to_regexp(symbol)
38
+ @@sym_to_regexp[symbol] || raise(ArgumentError.new("Symbol (#{symbol}) Found"))
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -14,8 +14,6 @@ module Bc
14
14
  is_match(@actual, @pattern)
15
15
  end
16
16
 
17
- # does_not_maches?(actual) # uses failure_message_for_should_not
18
-
19
17
  def description
20
18
  "match to #{@pattern.inspect}"
21
19
  end
@@ -1,7 +1,7 @@
1
1
  module Bc
2
2
  module RSpec
3
3
  module Matchers
4
- VERSION = "0.0.3"
4
+ VERSION = "0.0.4"
5
5
  end
6
6
  end
7
7
  end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ require "bc-rspec-matchers/content_type"
4
+
5
+ describe Bc::RSpec::Matchers::ContentType do
6
+ shared_examples_for "format" do |format, options|
7
+ it { should match_to("Content-Type" => "application/#{format}; charset=utf-8") }
8
+ it { should match_to("Content-Type" => "application/#{format};charset=utf-8") }
9
+
10
+ wrong_formats = options && options[:wrong_formats]
11
+ wrong_formats && wrong_formats.each do |wrong_format|
12
+ it { should_not match_to("Content-Type" => "application/#{wrong_format}; charset=utlf-8") }
13
+ end
14
+ end
15
+
16
+ describe "created with :json" do
17
+ subject do
18
+ Bc::RSpec::Matchers::ContentType.new(:json)
19
+ end
20
+ it_should_behave_like "format", "json", :wrong_formats => ["xml"]
21
+ end
22
+
23
+ describe "created with 'json'" do
24
+ subject do
25
+ Bc::RSpec::Matchers::ContentType.new('json')
26
+ end
27
+ it_should_behave_like "format", "json", :wrong_formats => ["xml"]
28
+ end
29
+ end
@@ -83,7 +83,7 @@ describe Bc::RSpec::Matchers::DataStructure do
83
83
  Bc::RSpec::Matchers::DataStructure.new(["string"])
84
84
  end
85
85
 
86
- it { should match_to(["string"]) }
86
+ it { should match_to(["string"]) }
87
87
  it { should_not match_to([:symbol, "string"]) }
88
88
  it { should_not match_to(["string", :symbol]) }
89
89
  it { should_not match_to([:string]) }
@@ -104,5 +104,20 @@ describe Bc::RSpec::Matchers::DataStructure do
104
104
  it { should match_to({:every => "hash"}) }
105
105
  it { should_not match_to([]) }
106
106
  it { should_not match_to(nil) }
107
+
108
+ its(:description) { should == "match to {}" }
109
+ end
110
+
111
+ describe "created with {:key => 'value'}" do
112
+ subject do
113
+ Bc::RSpec::Matchers::DataStructure.new({:key => 'value'})
114
+ end
115
+
116
+ it { should match_to({:key => 'value'}) }
117
+ it { should match_to({:key => 'value', :key2 => 'value2'}) }
118
+ it { should_not match_to({}) }
119
+ it { should_not match_to(nil) }
120
+
121
+ its(:description) { should == "match to #{{:key => 'value'}.inspect}" }
107
122
  end
108
123
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bc-rspec-matchers
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Byclosure
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-09-09 00:00:00 Z
18
+ date: 2012-10-07 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  version_requirements: &id001 !ruby/object:Gem::Requirement
@@ -91,9 +91,11 @@ files:
91
91
  - Rakefile
92
92
  - bc-rspec-matchers.gemspec
93
93
  - lib/bc-rspec-matchers.rb
94
+ - lib/bc-rspec-matchers/content_type.rb
94
95
  - lib/bc-rspec-matchers/data_structure.rb
95
96
  - lib/bc-rspec-matchers/version.rb
96
97
  - spec/spec_helper.rb
98
+ - spec/unit/content_type_spec.rb
97
99
  - spec/unit/data_structure_spec.rb
98
100
  homepage: http://github.com/Byclosure/bc-rspec-matchers
99
101
  licenses: []
@@ -130,4 +132,5 @@ specification_version: 3
130
132
  summary: Collection of rspec matchers to improve spec writing performance
131
133
  test_files:
132
134
  - spec/spec_helper.rb
135
+ - spec/unit/content_type_spec.rb
133
136
  - spec/unit/data_structure_spec.rb