smartdown 0.14.0 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  module Smartdown
2
2
  module Model
3
3
  module Scenarios
4
- Scenario = Struct.new(:description, :question_groups, :outcome, :markers)
4
+ Scenario = Struct.new(:description, :question_groups, :outcome, :markers, :exact_markers)
5
5
  end
6
6
  end
7
7
  end
@@ -15,7 +15,8 @@ module Smartdown
15
15
  description,
16
16
  question_groups,
17
17
  outcome,
18
- markers
18
+ markers,
19
+ exact_markers
19
20
  )
20
21
  end
21
22
 
@@ -30,31 +31,44 @@ module Smartdown
30
31
  end
31
32
 
32
33
  def question_groups
33
- lines = @scenario_lines - description_lines
34
- if has_markers?
35
- question_pages = group_questions_by_page(lines[0..-3])
36
- else
37
- question_pages = group_questions_by_page(lines[0..-2])
38
- end
34
+ question_pages = group_questions_by_page(@scenario_lines[first_question..last_question])
39
35
  question_groups = question_pages.map { |question_page| interpret_question_page(question_page) }
40
36
  end
41
37
 
38
+ def last_question
39
+ @scenario_lines.rindex { |line| line.match(/(\s\s\S*:)|(- \S*:)/) }
40
+ end
41
+
42
+ def first_question
43
+ @scenario_lines.index { |line| line.match(/(\s\s\S*:)|(- \S*:)/) }
44
+ end
45
+
42
46
  def outcome
43
- if has_markers?
44
- @scenario_lines[@scenario_lines.size - 2]
45
- else
46
- @scenario_lines.last
47
- end
47
+ @scenario_lines[last_question + 1]
48
48
  end
49
49
 
50
50
  def has_markers?
51
- @scenario_lines.last.match(/(has markers:|has marker:)/)
51
+ @scenario_lines.any? { |line| line.match(/(has markers:|has marker:)/) }
52
+ end
53
+
54
+ def has_exact_markers?
55
+ @scenario_lines.any? { |line| line.match(/(exact markers:|exact marker:)/) }
52
56
  end
53
57
 
54
58
  def markers
55
59
  if has_markers?
56
- last_line = @scenario_lines.last
57
- comma_sperated_markers = last_line.slice(last_line.index(":") + 1, last_line.size)
60
+ marker_line = @scenario_lines.find { |line| line.match(/(has markers:|has marker:)/) }
61
+ comma_sperated_markers = marker_line.slice(marker_line.index(":") + 1, marker_line.size)
62
+ comma_sperated_markers.split(',').map(&:strip)
63
+ else
64
+ []
65
+ end
66
+ end
67
+
68
+ def exact_markers
69
+ if has_exact_markers?
70
+ marker_line = @scenario_lines.find { |line| line.match(/(exact markers:|exact marker:)/) }
71
+ comma_sperated_markers = marker_line.slice(marker_line.index(":") + 1, marker_line.size)
58
72
  comma_sperated_markers.split(',').map(&:strip)
59
73
  else
60
74
  []
@@ -1,3 +1,3 @@
1
1
  module Smartdown
2
- VERSION = "0.14.0"
2
+ VERSION = "0.15.0"
3
3
  end
@@ -2,4 +2,5 @@
2
2
  # And cats are amazing
3
3
  - question_1: cat
4
4
  outcome_safe_pet
5
- has markers: is_a_safe_pet, safe_pets_are_cool
5
+ has marker: is_a_safe_pet
6
+ exact markers: is_a_safe_pet, safe_pets_are_cool
@@ -1,8 +1,8 @@
1
1
  require 'smartdown/parser/scenario_set_interpreter'
2
2
 
3
3
  describe Smartdown::Parser::ScenarioSetInterpreter do
4
- let(:outcome) { File.open(File.dirname(__FILE__) + "/../fixtures/acceptance/animal-example-simple/scenarios/tigers_and_cats.txt", "rb").read }
5
- subject { described_class.new(outcome) }
4
+ let(:scenario) { File.open(File.dirname(__FILE__) + "/../fixtures/acceptance/animal-example-simple/scenarios/tigers_and_cats.txt", "rb").read }
5
+ subject { described_class.new(scenario) }
6
6
 
7
7
  describe "#description" do
8
8
  it { expect(subject.description).to eq("User has a cat;And cats are amazing") }
@@ -17,8 +17,10 @@ describe Smartdown::Parser::ScenarioSetInterpreter do
17
17
  end
18
18
 
19
19
  describe "#markers" do
20
- it { expect(subject.markers).to eq(["is_a_safe_pet", "safe_pets_are_cool"]) }
20
+ it { expect(subject.markers).to eq(["is_a_safe_pet"]) }
21
21
  end
22
22
 
23
-
23
+ describe "#exact_markers" do
24
+ it { expect(subject.exact_markers).to eq(["is_a_safe_pet", "safe_pets_are_cool"]) }
25
+ end
24
26
  end
@@ -25,7 +25,8 @@ describe Smartdown::Parser::ScenarioSetsInterpreter do
25
25
  expect(tigers_and_cats_scenario_set.scenarios.first.description).to eq("User has a cat;And cats are amazing")
26
26
  expect(tigers_and_cats_scenario_set.scenarios.first.question_groups.size).to eq(1)
27
27
  expect(tigers_and_cats_scenario_set.scenarios.first.outcome).to eq("outcome_safe_pet")
28
- expect(tigers_and_cats_scenario_set.scenarios.first.markers).to eq(['is_a_safe_pet', 'safe_pets_are_cool'])
28
+ expect(tigers_and_cats_scenario_set.scenarios.first.markers).to eq(['is_a_safe_pet'])
29
+ expect(tigers_and_cats_scenario_set.scenarios.first.exact_markers).to eq(['is_a_safe_pet', 'safe_pets_are_cool'])
29
30
  end
30
31
 
31
32
  it "has scenario questions with name and answer" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smartdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.0
4
+ version: 0.15.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-03-24 00:00:00.000000000 Z
12
+ date: 2015-04-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: parslet
16
- requirement: &23997380 !ruby/object:Gem::Requirement
16
+ requirement: &9427800 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.6.2
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *23997380
24
+ version_requirements: *9427800
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: uk_postcode
27
- requirement: &23996560 !ruby/object:Gem::Requirement
27
+ requirement: &9427020 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.0.1
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *23996560
35
+ version_requirements: *9427020
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &24022840 !ruby/object:Gem::Requirement
38
+ requirement: &9453240 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 3.0.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *24022840
46
+ version_requirements: *9453240
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rake
49
- requirement: &24022300 !ruby/object:Gem::Requirement
49
+ requirement: &9452780 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *24022300
57
+ version_requirements: *9452780
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: pry
60
- requirement: &24021740 !ruby/object:Gem::Requirement
60
+ requirement: &9452180 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *24021740
68
+ version_requirements: *9452180
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: gem_publisher
71
- requirement: &24021220 !ruby/object:Gem::Requirement
71
+ requirement: &9451440 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *24021220
79
+ version_requirements: *9451440
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: timecop
82
- requirement: &24020020 !ruby/object:Gem::Requirement
82
+ requirement: &9450080 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,7 +87,7 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *24020020
90
+ version_requirements: *9450080
91
91
  description:
92
92
  email: david.heath@digital.cabinet-office.gov.uk
93
93
  executables:
@@ -315,7 +315,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
315
315
  version: '0'
316
316
  segments:
317
317
  - 0
318
- hash: -4151966028766809979
318
+ hash: 4167639428547367493
319
319
  required_rubygems_version: !ruby/object:Gem::Requirement
320
320
  none: false
321
321
  requirements:
@@ -324,7 +324,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
324
324
  version: '0'
325
325
  segments:
326
326
  - 0
327
- hash: -4151966028766809979
327
+ hash: 4167639428547367493
328
328
  requirements: []
329
329
  rubyforge_project:
330
330
  rubygems_version: 1.8.11