Skip to content

Commit

Permalink
Use the shared examples in the preexisting tests
Browse files Browse the repository at this point in the history
this also serves to test the cwm/rspec testing library and have it
contribute to testing coverage stats
  • Loading branch information
mvidner committed May 16, 2017
1 parent 754feb7 commit 0f67b1b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
3 changes: 3 additions & 0 deletions library/cwm/test/abstract_widget_test.rb
Expand Up @@ -3,8 +3,11 @@
require_relative "test_helper"

require "cwm/abstract_widget"
require "cwm/rspec"

describe CWM::AbstractWidget do
include_examples "CWM::AbstractWidget"

describe "#widget_id" do
class T1 < CWM::AbstractWidget
def initialize(id: nil)
Expand Down
37 changes: 22 additions & 15 deletions library/cwm/test/custom_widget_test.rb
@@ -1,27 +1,34 @@
require_relative "test_helper"

require "cwm/custom_widget"
require "cwm/rspec"

describe CWM::CustomWidget do
describe "#description" do
context "handle_all_events is false" do
class CustomTestWidget < CWM::CustomWidget
def initialize
self.handle_all_events = false
self.widget_id = "test_widget"
end
class CustomTestWidget < CWM::CustomWidget
def contents
HBox(
InputField(Id(:first), "test"),
PushButton(Id("second"), "Discover 42")
)
end
end
subject { CustomTestWidget.new }

def contents
HBox(
InputField(Id(:first), "test"),
PushButton(Id("second"), "Discover 42")
)
end
include_examples "CWM::CustomWidget"

context "handle_all_events is false" do
class IsolationistTestWidget < CustomTestWidget
def initialize
self.handle_all_events = false
self.widget_id = "test_widget"
end
subject { CustomTestWidget.new }
end
describe "#cwm_definition" do
subject { IsolationistTestWidget.new }

it "adds to description to handle only ids in contents and widget_id" do
expect(subject.cwm_definition["handle_events"]).to eq [:first, "second", "test_widget"]
expect(subject.cwm_definition["handle_events"])
.to eq [:first, "second", "test_widget"]
end
end
end
Expand Down
3 changes: 3 additions & 0 deletions library/cwm/test/widgets_test.rb
Expand Up @@ -3,6 +3,7 @@
require_relative "test_helper"

require "cwm/widget"
require "cwm/rspec"

describe CWM::RadioButtons do

Expand Down Expand Up @@ -87,6 +88,8 @@ def cleanup
end
end

include_examples "CWM::CustomWidget"

describe ".new" do
it "has widget_id as passed" do
subject = described_class.new(id: "test")
Expand Down

0 comments on commit 0f67b1b

Please sign in to comment.