Module: PlanMyStuff::TestHelpers
- Defined in:
- lib/plan_my_stuff/test_helpers.rb
Overview
Test support for consuming apps. Provides:
-
‘PlanMyStuff.test_mode!` to stub all API calls
-
Factory-style builders: ‘build_issue`, `build_comment`, `build_project`
-
RSpec matchers: ‘expect_pms_issue_created`, `expect_pms_comment_created`, `expect_pms_item_moved`
Usage:
require 'plan_my_stuff/test_helpers'
RSpec.configure do |config|
config.include PlanMyStuff::TestHelpers
end
Class Method Summary collapse
-
.build_comment(body: 'Test comment', visibility: :public, id: 1, issue: nil, metadata: {}) ⇒ PlanMyStuff::Comment
Builds a fake persisted Comment without hitting the API.
-
.build_issue(title: 'Test Issue', body: 'Test body', state: :open, number: 1, repo: 'TestOrg/TestRepo', labels: [], metadata: {}) ⇒ PlanMyStuff::Issue
Builds a fake persisted Issue without hitting the API.
-
.build_project(title: 'Test Project', number: 1, statuses: [], items: []) ⇒ PlanMyStuff::Project
Builds a fake persisted Project without hitting the API.
Instance Method Summary collapse
- #expect_pms_comment_created(**filters) ⇒ Object
- #expect_pms_comment_updated(**filters) ⇒ Object
- #expect_pms_comments_listed(**filters) ⇒ Object
- #expect_pms_issue_created(**filters) ⇒ Object
- #expect_pms_issue_found(**filters) ⇒ Object
- #expect_pms_issue_updated(**filters) ⇒ Object
- #expect_pms_issues_listed(**filters) ⇒ Object
- #expect_pms_item_assigned(**filters) ⇒ Object
- #expect_pms_item_created(**filters) ⇒ Object
- #expect_pms_item_moved(**filters) ⇒ Object
- #expect_pms_project_found(**filters) ⇒ Object
- #expect_pms_projects_listed(**filters) ⇒ Object
- #expect_pms_viewers_added(**filters) ⇒ Object
- #expect_pms_viewers_removed(**filters) ⇒ Object
Class Method Details
.build_comment(body: 'Test comment', visibility: :public, id: 1, issue: nil, metadata: {}) ⇒ PlanMyStuff::Comment
Builds a fake persisted Comment without hitting the API.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/plan_my_stuff/test_helpers.rb', line 84 def build_comment(body: 'Test comment', visibility: :public, id: 1, issue: nil, metadata: {}) issue ||= build_issue comment = PlanMyStuff::Comment.new( body: body, id: id, issue: issue, ) comment.visibility = visibility.to_sym = PlanMyStuff::CommentMetadata.from_hash({ schema_version: PlanMyStuff::BaseMetadata::SCHEMA_VERSION, gem_version: PlanMyStuff::VERSION::STRING, visibility: visibility.to_s, custom_fields: {}, }.merge()) comment.instance_variable_set(:@metadata, ) comment.instance_variable_set(:@persisted, true) comment end |
.build_issue(title: 'Test Issue', body: 'Test body', state: :open, number: 1, repo: 'TestOrg/TestRepo', labels: [], metadata: {}) ⇒ PlanMyStuff::Issue
Builds a fake persisted Issue without hitting the API.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/plan_my_stuff/test_helpers.rb', line 36 def build_issue( title: 'Test Issue', body: 'Test body', state: :open, number: 1, repo: 'TestOrg/TestRepo', labels: [], metadata: {} ) issue = PlanMyStuff::Issue.new( title: title, body: body, state: state.to_s, number: number, repo: repo, labels: labels, ) = PlanMyStuff::IssueMetadata.from_hash({ schema_version: PlanMyStuff::BaseMetadata::SCHEMA_VERSION, gem_version: PlanMyStuff::VERSION::STRING, visibility: 'public', custom_fields: {}, }.merge()) issue.instance_variable_set(:@metadata, ) issue.instance_variable_set(:@persisted, true) body_comment = build_comment( body: body, issue: issue, metadata: { issue_body: true }, ) issue.instance_variable_set(:@comments, [body_comment]) issue end |
.build_project(title: 'Test Project', number: 1, statuses: [], items: []) ⇒ PlanMyStuff::Project
Builds a fake persisted Project without hitting the API.
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/plan_my_stuff/test_helpers.rb', line 115 def build_project(title: 'Test Project', number: 1, statuses: [], items: []) = statuses.each_with_index.map do |name, i| { id: "status_option_#{i}", name: name } end project = PlanMyStuff::Project.new( id: "PVT_fake_#{number}", number: number, title: title, statuses: , fields: [{ id: 'field_status', name: 'Status', options: }], ) project.instance_variable_set(:@persisted, true) project.items = items.map do |item_hash| PlanMyStuff::ProjectItem.build( { id: item_hash[:id] || "PVTI_fake_#{rand(10_000)}", title: item_hash[:title] || 'Untitled', number: item_hash[:number], url: item_hash[:url], state: item_hash[:state], status: item_hash[:status], field_values: item_hash[:field_values] || {}, }, project: project, ) end project end |
Instance Method Details
#expect_pms_comment_created(**filters) ⇒ Object
182 183 184 |
# File 'lib/plan_my_stuff/test_helpers.rb', line 182 def expect_pms_comment_created(**filters) expect_pms_action(:comment_created, 'comment to be created', **filters) end |
#expect_pms_comment_updated(**filters) ⇒ Object
192 193 194 |
# File 'lib/plan_my_stuff/test_helpers.rb', line 192 def expect_pms_comment_updated(**filters) expect_pms_action(:comment_updated, 'comment to be updated', **filters) end |
#expect_pms_comments_listed(**filters) ⇒ Object
187 188 189 |
# File 'lib/plan_my_stuff/test_helpers.rb', line 187 def expect_pms_comments_listed(**filters) expect_pms_action(:comments_listed, 'comments to be listed', **filters) end |
#expect_pms_issue_created(**filters) ⇒ Object
152 153 154 |
# File 'lib/plan_my_stuff/test_helpers.rb', line 152 def expect_pms_issue_created(**filters) expect_pms_action(:issue_created, 'issue to be created', **filters) end |
#expect_pms_issue_found(**filters) ⇒ Object
157 158 159 |
# File 'lib/plan_my_stuff/test_helpers.rb', line 157 def expect_pms_issue_found(**filters) expect_pms_action(:issue_found, 'issue to be found', **filters) end |
#expect_pms_issue_updated(**filters) ⇒ Object
167 168 169 |
# File 'lib/plan_my_stuff/test_helpers.rb', line 167 def expect_pms_issue_updated(**filters) expect_pms_action(:issue_updated, 'issue to be updated', **filters) end |
#expect_pms_issues_listed(**filters) ⇒ Object
162 163 164 |
# File 'lib/plan_my_stuff/test_helpers.rb', line 162 def expect_pms_issues_listed(**filters) expect_pms_action(:issues_listed, 'issues to be listed', **filters) end |
#expect_pms_item_assigned(**filters) ⇒ Object
217 218 219 |
# File 'lib/plan_my_stuff/test_helpers.rb', line 217 def expect_pms_item_assigned(**filters) expect_pms_action(:item_assigned, 'item to be assigned', **filters) end |
#expect_pms_item_created(**filters) ⇒ Object
212 213 214 |
# File 'lib/plan_my_stuff/test_helpers.rb', line 212 def expect_pms_item_created(**filters) expect_pms_action(:item_created, 'item to be created', **filters) end |
#expect_pms_item_moved(**filters) ⇒ Object
207 208 209 |
# File 'lib/plan_my_stuff/test_helpers.rb', line 207 def expect_pms_item_moved(**filters) expect_pms_action(:item_moved, 'item to be moved', **filters) end |
#expect_pms_project_found(**filters) ⇒ Object
202 203 204 |
# File 'lib/plan_my_stuff/test_helpers.rb', line 202 def expect_pms_project_found(**filters) expect_pms_action(:project_found, 'project to be found', **filters) end |
#expect_pms_projects_listed(**filters) ⇒ Object
197 198 199 |
# File 'lib/plan_my_stuff/test_helpers.rb', line 197 def expect_pms_projects_listed(**filters) expect_pms_action(:projects_listed, 'projects to be listed', **filters) end |
#expect_pms_viewers_added(**filters) ⇒ Object
172 173 174 |
# File 'lib/plan_my_stuff/test_helpers.rb', line 172 def expect_pms_viewers_added(**filters) expect_pms_action(:viewers_added, 'viewers to be added', **filters) end |
#expect_pms_viewers_removed(**filters) ⇒ Object
177 178 179 |
# File 'lib/plan_my_stuff/test_helpers.rb', line 177 def expect_pms_viewers_removed(**filters) expect_pms_action(:viewers_removed, 'viewers to be removed', **filters) end |