Skip to content

Commit

Permalink
Make test coverage data available for smart answer flows
Browse files Browse the repository at this point in the history
This is a "spike" which demonstrates how to obtain test coverage data for
the `additional-commodity-code` flow. This data was not previously
available [1], because the flow files were being read and eval'ed rather than
simply required. The latter is necessary [2] for `SimpleCov` to record coverage
data for the file.

By extracting the existing DSL code into a `define` method on a subclass of
`SmartAnswer::Flow`, we can safely require the file separately from
instantiating the flow. This feels like a better state of affairs in general,
but it specifically addresses the test coverage problem above.

We'd really like to have this coverage data available so we can have confidence
that we're not breaking anything as we continue to refactor the app.

Note that I've intentionally not fixed the indentation in the
`additional-commodity-code` flow file so that it's easier to see my changes.

[1]: https://ci-new.alphagov.co.uk/job/govuk_smart_answers/2396/rcov/
[2]: simplecov-ruby/simplecov#38
  • Loading branch information
floehopper committed May 14, 2015
1 parent d5bff79 commit 3474cd5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
16 changes: 12 additions & 4 deletions lib/smart_answer/flow_registry.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require "smart_answer_flows/additional-commodity-code"

module SmartAnswer
class FlowRegistry
class NotFound < StandardError; end
Expand Down Expand Up @@ -51,10 +53,16 @@ def available?(name)
end

def build_flow(name)
absolute_path = @load_path.join("#{name}.rb").to_s
Flow.new do
eval(File.read(absolute_path), binding, absolute_path)
name(name)
if name == 'additional-commodity-code'
flow = AdditionalCommodityCode.new
flow.define
flow
else
absolute_path = @load_path.join("#{name}.rb").to_s
Flow.new do
eval(File.read(absolute_path), binding, absolute_path)
name(name)
end
end
end

Expand Down
11 changes: 11 additions & 0 deletions lib/smart_answer_flows/additional-commodity-code.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
module SmartAnswer

class AdditionalCommodityCode < Flow

def define
name 'additional-commodity-code'

status :published
satisfies_need "100233"

Expand Down Expand Up @@ -188,3 +195,7 @@
end
end
end

end
end
end

0 comments on commit 3474cd5

Please sign in to comment.