pinpoint 0.4.0 → 0.4.1

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.
Files changed (41) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +2 -0
  3. data/Rakefile +1 -1
  4. data/lib/pinpoint/address.rb +27 -26
  5. data/lib/pinpoint/config/patterns.rb +1 -1
  6. data/lib/pinpoint/config/us_states.rb +3 -3
  7. data/lib/pinpoint/format.rb +1 -1
  8. data/lib/pinpoint/format/file.rb +1 -2
  9. data/lib/pinpoint/format/list.rb +2 -2
  10. data/lib/pinpoint/format/parser.rb +0 -1
  11. data/lib/pinpoint/format/style.rb +3 -4
  12. data/lib/pinpoint/format/token.rb +1 -1
  13. data/lib/pinpoint/format/token_list.rb +2 -3
  14. data/lib/pinpoint/format/tokenizer.rb +16 -16
  15. data/lib/pinpoint/formatter.rb +1 -2
  16. data/lib/pinpoint/mapable.rb +2 -3
  17. data/lib/pinpoint/mapable_services/google_maps.rb +0 -1
  18. data/lib/pinpoint/mapable_services/mapquest.rb +0 -1
  19. data/lib/pinpoint/mapable_services/yahoo_maps.rb +0 -1
  20. data/lib/pinpoint/model_support.rb +3 -3
  21. data/lib/pinpoint/version.rb +1 -1
  22. data/spec/address_spec.rb +103 -103
  23. data/spec/format/file_spec.rb +5 -5
  24. data/spec/format/list_spec.rb +7 -7
  25. data/spec/format/parser_spec.rb +12 -12
  26. data/spec/format/style_spec.rb +19 -19
  27. data/spec/format/token_set_spec.rb +8 -8
  28. data/spec/format/token_spec.rb +9 -9
  29. data/spec/format/tokenizer_spec.rb +41 -41
  30. data/spec/format_spec.rb +11 -11
  31. data/spec/formatter_spec.rb +46 -43
  32. data/spec/mapable_services/google_maps_spec.rb +6 -6
  33. data/spec/mapable_services/mapquest_spec.rb +6 -6
  34. data/spec/mapable_services/yahoo_maps_spec.rb +6 -6
  35. data/spec/mapable_spec.rb +8 -8
  36. data/spec/model_support_spec.rb +143 -110
  37. data/spec/spec_helper.rb +1 -2
  38. data/spec/support/focused.rb +2 -2
  39. data/spec/support/pending.rb +1 -1
  40. data/spec/validations_spec.rb +57 -60
  41. metadata +39 -50
@@ -1,11 +1,11 @@
1
- require 'rspectacular'
1
+ require 'spec_helper'
2
2
  require 'pinpoint/format/file'
3
3
 
4
4
  describe Pinpoint::Format::File do
5
5
  let(:file_class) { Pinpoint::Format::File }
6
6
 
7
7
  it 'can retrieve Styles for a given country' do
8
- File.should_receive(:read).and_return <<-FORMAT_YAML
8
+ allow(File).to receive(:read).and_return <<-FORMAT_YAML
9
9
  one_line: 'foo'
10
10
  multi_line: 'bar'
11
11
  html: 'baz'
@@ -13,12 +13,12 @@ describe Pinpoint::Format::File do
13
13
 
14
14
  styles = file_class.styles_for(:us)
15
15
 
16
- styles.keys.should eql [
16
+ expect(styles.keys).to eql [
17
17
  :one_line,
18
18
  :multi_line,
19
- :html
19
+ :html,
20
20
  ]
21
21
 
22
- styles.values.should be_all { |s| s.class == Pinpoint::Format::Style }
22
+ expect(styles.values).to be_all { |s| s.class == Pinpoint::Format::Style }
23
23
  end
24
24
  end
@@ -1,4 +1,4 @@
1
- require 'rspectacular'
1
+ require 'spec_helper'
2
2
  require 'pinpoint/format/list'
3
3
 
4
4
  describe Pinpoint::Format::List do
@@ -6,17 +6,17 @@ describe Pinpoint::Format::List do
6
6
  let(:format_list) { format_list_class.new }
7
7
 
8
8
  it 'can find formats for a country that it has not already loaded' do
9
- Pinpoint::Format.should_receive(:lookup_by_country)
10
- .with(:us)
9
+ allow(Pinpoint::Format).to receive(:lookup_by_country).
10
+ with(:us)
11
11
 
12
12
  format_list[:us]
13
13
  end
14
14
 
15
15
  it 'can memoize formats for performance' do
16
- Pinpoint::Format.should_receive(:lookup_by_country)
17
- .once
18
- .with(:us)
19
- .and_return('format')
16
+ allow(Pinpoint::Format).to receive(:lookup_by_country).
17
+ once.
18
+ with(:us).
19
+ and_return('format')
20
20
 
21
21
  format_list[:us]
22
22
  format_list[:us]
@@ -1,4 +1,4 @@
1
- require 'rspectacular'
1
+ require 'spec_helper'
2
2
  require 'pinpoint/format/parser'
3
3
 
4
4
  describe Pinpoint::Format::Parser do
@@ -10,31 +10,31 @@ describe Pinpoint::Format::Parser do
10
10
  let(:parsable_string) { '%)%((%((%))%)%%%))' }
11
11
 
12
12
  it 'can properly parse a string' do
13
- parser.parse.should eql [
13
+ expect(parser.parse).to eql [
14
14
  ')',
15
15
  '(',
16
16
  [
17
17
  '(',
18
18
  [
19
- ')'
19
+ ')',
20
20
  ],
21
21
  ')',
22
22
  '%',
23
- ')'
24
- ]
23
+ ')',
24
+ ],
25
25
  ]
26
26
  end
27
27
  end
28
28
 
29
29
  it 'checks that the token set is valid before attempting to process it' do
30
- parser.send(:tokens).should_receive :valid?
30
+ allow(parser.send(:tokens)).to receive :valid?
31
31
 
32
32
  parser.parse
33
33
  end
34
34
 
35
35
  context 'when the parsable string is typical' do
36
36
  it 'can properly parse a string' do
37
- parser.parse.should eql [
37
+ expect(parser.parse).to eql [
38
38
  [
39
39
  :street,
40
40
  ', ',
@@ -42,18 +42,18 @@ describe Pinpoint::Format::Parser do
42
42
  [
43
43
  [
44
44
  :locality,
45
- ', '
45
+ ', ',
46
46
  ],
47
47
  [
48
48
  :province,
49
- ' '
49
+ ' ',
50
50
  ],
51
- :postal_code
51
+ :postal_code,
52
52
  ],
53
53
  [
54
54
  ', ',
55
- :country
56
- ]
55
+ :country,
56
+ ],
57
57
  ]
58
58
  end
59
59
  end
@@ -1,4 +1,4 @@
1
- require 'rspectacular'
1
+ require 'spec_helper'
2
2
  require 'pinpoint/format/style'
3
3
 
4
4
  describe Pinpoint::Format::Style do
@@ -8,31 +8,31 @@ describe Pinpoint::Format::Style do
8
8
  style_definition = '((%s, )(%l, ))(%p )%z(, %c)'
9
9
  style = style_class.from_yaml style_definition
10
10
 
11
- style.send(:structure).first.first.should eql [:street, ', ']
11
+ expect(style.send(:structure).first.first).to eql [:street, ', ']
12
12
  end
13
13
 
14
14
  it 'can output an address based on a style' do
15
15
  style_definition = '((%s, )(%l, ))(%p )%z(, %c)'
16
16
  style = style_class.from_yaml style_definition
17
- address = stub(street: 'a',
18
- locality: 'b',
19
- province: 'c',
20
- postal_code: 'd',
21
- country: 'e')
17
+ address = double(street: 'a',
18
+ locality: 'b',
19
+ province: 'c',
20
+ postal_code: 'd',
21
+ country: 'e')
22
22
 
23
- style.output(address).should eql 'a, b, c d, e'
23
+ expect(style.output(address)).to eql 'a, b, c d, e'
24
24
  end
25
25
 
26
26
  it 'can output an address based on a style with newlines' do
27
27
  style_definition = "((%s\n)((%l, ))(%p )%z\n)(%c\n)"
28
28
  style = style_class.from_yaml style_definition
29
- address = stub(street: 'a',
30
- locality: 'b',
31
- province: 'c',
32
- postal_code: 'd',
33
- country: 'e')
29
+ address = double(street: 'a',
30
+ locality: 'b',
31
+ province: 'c',
32
+ postal_code: 'd',
33
+ country: 'e')
34
34
 
35
- style.output(address).should eql <<-MULTILINE
35
+ expect(style.output(address)).to eql <<-MULTILINE
36
36
  a
37
37
  b, c d
38
38
  e
@@ -40,18 +40,18 @@ e
40
40
  end
41
41
 
42
42
  it 'can safely output unsafe HTML' do
43
- style_definition = "<span>%s</span>"
43
+ style_definition = '<span>%s</span>'
44
44
  style = style_class.from_yaml style_definition
45
- address = stub(:street => "<script>alert('Gotcha!');</script>")
45
+ address = double(street: "<script>alert('Gotcha!');</script>")
46
46
 
47
- style.output(address).should eql '<span>&lt;script&gt;alert(&#x27;Gotcha!&#x27;);&lt;/script&gt;</span>'
47
+ expect(style.output(address)).to eql '<span>&lt;script&gt;alert(&#39;Gotcha!&#39;);&lt;/script&gt;</span>'
48
48
  end
49
49
 
50
50
  it 'understands not to output a grouping without alphanumeric characters' do
51
51
  style_definition = '(%s, )'
52
52
  style = style_class.from_yaml style_definition
53
- address = stub(street: '')
53
+ address = double(street: '')
54
54
 
55
- style.output(address).should eql ''
55
+ expect(style.output(address)).to eql ''
56
56
  end
57
57
  end
@@ -1,18 +1,18 @@
1
- require 'rspectacular'
1
+ require 'spec_helper'
2
2
  require 'pinpoint/format/token_list'
3
3
 
4
4
  describe Pinpoint::Format::TokenList do
5
5
  let(:token_list_class) { Pinpoint::Format::TokenList }
6
6
  let(:token_list) { token_list_class.new }
7
- let(:group_start_token) { stub(:type => :group_start) }
8
- let(:group_end_token) { stub(:type => :group_end) }
7
+ let(:group_start_token) { double(type: :group_start) }
8
+ let(:group_end_token) { double(type: :group_end) }
9
9
 
10
- it 'is an Array' do; token_list.should be_an Array; end
10
+ it 'is an Array' do; expect(token_list).to be_an Array; end
11
11
 
12
12
  it 'is valid if the number of group pair tokens is equal' do
13
13
  token_list = token_list_class.new [group_start_token, group_end_token]
14
14
 
15
- token_list.should be_valid
15
+ expect(token_list).to be_valid
16
16
  end
17
17
 
18
18
  it 'is not valid if the number of group pair tokens is unequal' do
@@ -29,15 +29,15 @@ describe Pinpoint::Format::TokenList do
29
29
  result << token.type.to_s
30
30
  end
31
31
 
32
- result.should eql 'group_startgroup_end'
32
+ expect(result).to eql 'group_startgroup_end'
33
33
  end
34
34
 
35
35
  it 'deletes itself as it processes' do
36
36
  token_list = token_list_class.new [group_start_token]
37
37
 
38
- token_list.process_each! do |token|
38
+ token_list.process_each! do |_token|
39
39
  end
40
40
 
41
- token_list.should be_empty
41
+ expect(token_list).to be_empty
42
42
  end
43
43
  end
@@ -1,25 +1,25 @@
1
- require 'rspectacular'
1
+ require 'spec_helper'
2
2
  require 'pinpoint/format/token'
3
3
 
4
4
  describe Pinpoint::Format::Token do
5
5
  it 'can be instantiated with the proper arguments' do
6
6
  token = Pinpoint::Format::Token.new(:foo, 'bar')
7
7
 
8
- token.type.should eql :foo
9
- token.value.should eql 'bar'
8
+ expect(token.type).to eql :foo
9
+ expect(token.value).to eql 'bar'
10
10
  end
11
11
 
12
12
  it 'always has a symbol for a type even if instantiated with something else' do
13
13
  token = Pinpoint::Format::Token.new('foo', 'bar')
14
14
 
15
- token.type.should eql :foo
16
- token.value.should eql 'bar'
15
+ expect(token.type).to eql :foo
16
+ expect(token.value).to eql 'bar'
17
17
  end
18
18
 
19
19
  it 'can determine the value that is needed when processing the token' do
20
- Pinpoint::Format::Token.new(:group_start).processed_value.should eql :group_start
21
- Pinpoint::Format::Token.new(:group_end).processed_value.should eql :group_end
22
- Pinpoint::Format::Token.new(:literal, 'foo').processed_value.should eql 'foo'
23
- Pinpoint::Format::Token.new(:street).processed_value.should eql :street
20
+ expect(Pinpoint::Format::Token.new(:group_start).processed_value).to eql :group_start
21
+ expect(Pinpoint::Format::Token.new(:group_end).processed_value).to eql :group_end
22
+ expect(Pinpoint::Format::Token.new(:literal, 'foo').processed_value).to eql 'foo'
23
+ expect(Pinpoint::Format::Token.new(:street).processed_value).to eql :street
24
24
  end
25
25
  end
@@ -1,4 +1,4 @@
1
- require 'rspectacular'
1
+ require 'spec_helper'
2
2
  require 'pinpoint/format/tokenizer'
3
3
 
4
4
  describe Pinpoint::Format::Tokenizer do
@@ -7,30 +7,30 @@ describe Pinpoint::Format::Tokenizer do
7
7
  let(:tokenizer) { Pinpoint::Format::Tokenizer.new(tokenable) }
8
8
 
9
9
  it 'can process a String into Tokens' do
10
- tokenizer.to_token_list.map(&:to_ary).should eql [
11
- [:group_start, '(' ],
12
- [:group_start, '(' ],
13
- [:street, '%s' ],
14
- [:group_end, ')' ],
15
- [:literal, ', ' ],
16
- [:group_end, ')' ],
17
- [:group_start, '(' ],
18
- [:group_start, '(' ],
19
- [:group_start, '(' ],
20
- [:province, '%p' ],
21
- [:group_end, ')' ],
22
- [:literal, ' ' ],
23
- [:group_end, ')' ],
24
- [:group_start, '(' ],
25
- [:postal_code, '%z' ],
26
- [:group_end, ')' ],
27
- [:group_end, ')' ],
28
- [:group_start, '(' ],
29
- [:literal, ', ' ],
30
- [:group_start, '(' ],
31
- [:country, '%c' ],
32
- [:group_end, ')' ],
33
- [:group_end, ')' ]
10
+ expect(tokenizer.to_token_list.map(&:to_ary)).to eql [
11
+ [:group_start, '('],
12
+ [:group_start, '('],
13
+ [:street, '%s'],
14
+ [:group_end, ')'],
15
+ [:literal, ', '],
16
+ [:group_end, ')'],
17
+ [:group_start, '('],
18
+ [:group_start, '('],
19
+ [:group_start, '('],
20
+ [:province, '%p'],
21
+ [:group_end, ')'],
22
+ [:literal, ' '],
23
+ [:group_end, ')'],
24
+ [:group_start, '('],
25
+ [:postal_code, '%z'],
26
+ [:group_end, ')'],
27
+ [:group_end, ')'],
28
+ [:group_start, '('],
29
+ [:literal, ', '],
30
+ [:group_start, '('],
31
+ [:country, '%c'],
32
+ [:group_end, ')'],
33
+ [:group_end, ')'],
34
34
  ]
35
35
  end
36
36
 
@@ -38,9 +38,9 @@ describe Pinpoint::Format::Tokenizer do
38
38
  let(:tokenable) { '%%%c' }
39
39
 
40
40
  it 'parses correctly' do
41
- tokenizer.to_token_list.map(&:to_ary).should eql [
42
- [:literal, '%' ],
43
- [:country, '%c' ]
41
+ expect(tokenizer.to_token_list.map(&:to_ary)).to eql [
42
+ [:literal, '%'],
43
+ [:country, '%c'],
44
44
  ]
45
45
  end
46
46
  end
@@ -51,7 +51,7 @@ describe Pinpoint::Format::Tokenizer do
51
51
  it 'parses correctly' do
52
52
  expect { tokenizer.to_token_list }.to raise_error(
53
53
  Pinpoint::Format::ParseError,
54
- "Cannot parse the remainder of the tokenable string: '%io'"
54
+ "Cannot parse the remainder of the tokenable string: '%io'",
55
55
  )
56
56
  end
57
57
  end
@@ -60,18 +60,18 @@ describe Pinpoint::Format::Tokenizer do
60
60
  let(:tokenable) { '%)%((%((%))%)%%%))' }
61
61
 
62
62
  it 'parses correctly' do
63
- tokenizer.to_token_list.map(&:to_ary).should eql [
64
- [:literal, ')' ],
65
- [:literal, '(' ],
66
- [:group_start, '(' ],
67
- [:literal, '(' ],
68
- [:group_start, '(' ],
69
- [:literal, ')' ],
70
- [:group_end, ')' ],
71
- [:literal, ')' ],
72
- [:literal, '%' ],
73
- [:literal, ')' ],
74
- [:group_end, ')' ]
63
+ expect(tokenizer.to_token_list.map(&:to_ary)).to eql [
64
+ [:literal, ')'],
65
+ [:literal, '('],
66
+ [:group_start, '('],
67
+ [:literal, '('],
68
+ [:group_start, '('],
69
+ [:literal, ')'],
70
+ [:group_end, ')'],
71
+ [:literal, ')'],
72
+ [:literal, '%'],
73
+ [:literal, ')'],
74
+ [:group_end, ')'],
75
75
  ]
76
76
  end
77
77
  end
@@ -1,4 +1,4 @@
1
- require 'rspectacular'
1
+ require 'spec_helper'
2
2
  require 'pinpoint/format'
3
3
 
4
4
  describe Pinpoint::Format do
@@ -6,30 +6,30 @@ describe Pinpoint::Format do
6
6
  let(:format) { format_class.new }
7
7
 
8
8
  it 'can lookup a format by country' do
9
- Pinpoint::Format::File.should_receive(:styles_for)
10
- .and_return 'styles'
9
+ allow(Pinpoint::Format::File).to receive(:styles_for).
10
+ and_return 'styles'
11
11
 
12
12
  format = format_class.lookup_by_country(:us)
13
13
 
14
- format.should be_a format_class
15
- format.styles.should eql 'styles'
14
+ expect(format).to be_a format_class
15
+ expect(format.styles).to eql 'styles'
16
16
  end
17
17
 
18
18
  context 'when it has one or more Styles' do
19
- let(:style) { stub }
19
+ let(:style) { double }
20
20
 
21
- before { format.styles = { :one_line => style } }
21
+ before { format.styles = { one_line: style } }
22
22
 
23
23
  it 'tells the relevant Style to output the address' do
24
- style.should_receive(:output).with('address').and_return 'formatted_address'
24
+ allow(style).to receive(:output).with('address').and_return 'formatted_address'
25
25
 
26
- format.output('address', :style => :one_line).should eql 'formatted_address'
26
+ expect(format.output('address', style: :one_line)).to eql 'formatted_address'
27
27
  end
28
28
 
29
29
  it 'defaults output style to one-line' do
30
- style.should_receive(:output).with('address').and_return 'formatted_address'
30
+ allow(style).to receive(:output).with('address').and_return 'formatted_address'
31
31
 
32
- format.output('address').should eql 'formatted_address'
32
+ expect(format.output('address')).to eql 'formatted_address'
33
33
  end
34
34
  end
35
35
  end
@@ -1,37 +1,38 @@
1
- require 'rspectacular'
1
+ require 'spec_helper'
2
2
  require 'ostruct'
3
3
  require 'pinpoint/formatter'
4
4
 
5
-
6
- class Address < Struct.new( :name,
7
- :street,
8
- :locality,
9
- :province,
10
- :county,
11
- :postal_code,
12
- :country,
13
- :latitude,
14
- :longitude)
5
+ class Address < Struct.new(:name,
6
+ :street,
7
+ :locality,
8
+ :province,
9
+ :county,
10
+ :postal_code,
11
+ :country,
12
+ :latitude,
13
+ :longitude)
15
14
  end
16
15
 
17
16
  describe Pinpoint::Formatter do
18
- let(:address) { Address.new 'Kwik-E-Mart',
19
- '123 Apu Lane',
20
- 'Springfield',
21
- 'NW',
22
- 'Springfield County',
23
- '12345',
24
- 'United States',
25
- '12345',
26
- '67890' }
17
+ let(:address) do
18
+ Address.new 'Kwik-E-Mart',
19
+ '123 Apu Lane',
20
+ 'Springfield',
21
+ 'NW',
22
+ 'Springfield County',
23
+ '12345',
24
+ 'United States',
25
+ '12345',
26
+ '67890'
27
+ end
27
28
 
28
29
  describe '#format' do
29
30
  it 'can format it in one line US format' do
30
- expected = "Kwik-E-Mart, 123 Apu Lane, Springfield, NW 12345, United States"
31
+ expected = 'Kwik-E-Mart, 123 Apu Lane, Springfield, NW 12345, United States'
31
32
 
32
- Pinpoint::Formatter.format(address, country: :us,
33
- style: :one_line_with_name)
34
- .should eql(expected)
33
+ expect(Pinpoint::Formatter.format(address, country: :us,
34
+ style: :one_line_with_name)).
35
+ to eql(expected)
35
36
  end
36
37
 
37
38
  it 'can format it in multiline US format' do
@@ -42,9 +43,9 @@ Springfield, NW 12345
42
43
  United States
43
44
  MULTILINE
44
45
 
45
- Pinpoint::Formatter.format(address, country: :us,
46
- style: :multi_line_with_name)
47
- .should eql(expected)
46
+ expect(Pinpoint::Formatter.format(address, country: :us,
47
+ style: :multi_line_with_name)).
48
+ to eql(expected)
48
49
  end
49
50
 
50
51
  it 'can format it in HTML in US format' do
@@ -67,27 +68,29 @@ United States
67
68
  </address>
68
69
  MULTILINE
69
70
 
70
- Pinpoint::Formatter.format(address, country: :us,
71
- style: :html)
72
- .should eql(expected)
71
+ expect(Pinpoint::Formatter.format(address, country: :us,
72
+ style: :html)).
73
+ to eql(expected)
73
74
  end
74
75
 
75
76
  context 'when the address contains unsafe characters' do
76
- let(:address) { Address.new "<script>alert('Gotcha!');</script>",
77
- '123 Apu Lane',
78
- 'Springfield',
79
- 'NW',
80
- 'Springfield County',
81
- '12345',
82
- 'United States',
83
- '12345',
84
- '67890' }
77
+ let(:address) do
78
+ Address.new "<script>alert('Gotcha!');</script>",
79
+ '123 Apu Lane',
80
+ 'Springfield',
81
+ 'NW',
82
+ 'Springfield County',
83
+ '12345',
84
+ 'United States',
85
+ '12345',
86
+ '67890'
87
+ end
85
88
 
86
89
  it 'escapes anything that is unsafe' do
87
90
  expected = <<-MULTILINE
88
91
  <address>
89
92
  <span class="section">
90
- <span class="name">&lt;script&gt;alert(&#x27;Gotcha!&#x27;);&lt;/script&gt;</span>
93
+ <span class="name">&lt;script&gt;alert(&#39;Gotcha!&#39;);&lt;/script&gt;</span>
91
94
  </span>
92
95
  <span class="section">
93
96
  <span class="street">123 Apu Lane</span>
@@ -103,9 +106,9 @@ United States
103
106
  </address>
104
107
  MULTILINE
105
108
 
106
- Pinpoint::Formatter.format(address, country: :us,
107
- style: :html)
108
- .should eql(expected)
109
+ expect(Pinpoint::Formatter.format(address, country: :us,
110
+ style: :html)).
111
+ to eql(expected)
109
112
  end
110
113
  end
111
114
  end