[yast-devel] rspec testing fails
Hello, I am trying to use rake test:unit with this branch: https://github.com/dwbenjamin/yast-hello-world/tree/testing-configuration When I run rake test:unit I get an error that the test not "nil" and I don't understand why. If someone could take a minute and fix the test or tell me how I would really appreciate the help. Thanks, David. -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org To contact the owner, e-mail: yast-devel+owner@opensuse.org
On Tue, 26 May 2020 16:54:14 -0600
"David Benjamin"
Hello,
I am trying to use rake test:unit with this branch: https://github.com/dwbenjamin/yast-hello-world/tree/testing-configuration
When I run rake test:unit I get an error that the test not "nil" and I don't understand why.
If someone could take a minute and fix the test or tell me how I would really appreciate the help.
Hi David, basically test is correct and behavior of method not if you expect that run method will return non-nil value ( I am not sure about it ). So to make test pass you probably want apply this diff: ``` diff --git a/src/lib/y2helloworld/main_module.rb b/src/lib/y2helloworld/main_module.rb index 13323b2..6dd61c8 100644 --- a/src/lib/y2helloworld/main_module.rb +++ b/src/lib/y2helloworld/main_module.rb @@ -37,7 +37,7 @@ module Y2HelloWorld log.info "Received #{input}" # Break the loop - break + return input end end ``` But be aware that this maybe is not ideal way, as it means that finish of client result with :cancel, which result in non-zero exit code aka program failure. So unless you want to check what dialog returns, I would keep current behavior where run return nil and just adapt test to expect nil instead of cancel. It will look this way: ``` diff --git a/test/main_module_test.rb b/test/main_module_test.rb index e5dbb7b..ba19fdf 100644 --- a/test/main_module_test.rb +++ b/test/main_module_test.rb @@ -21,8 +21,6 @@ describe Y2HelloWorld::MainDialog do it "return :cancel if user closes window" do mock_dialog :input => :cancel - expect(Y2HelloWorld::MainDialog.new.run).to eq :cancel + expect(Y2HelloWorld::MainDialog.new.run).to eq nil end - - -end \ No newline at end of file +end ``` I hope that it helps. Josef
Thanks, David.
-- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org To contact the owner, e-mail: yast-devel+owner@opensuse.org
participants (2)
-
David Benjamin
-
josef Reidinger