Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remember command's optoins #60

Merged
merged 11 commits into from
Aug 25, 2014
Merged

Remember command's optoins #60

merged 11 commits into from
Aug 25, 2014

Conversation

andriiNyzhnik
Copy link

Store options in file in home folder.
Use just '.tddium' file, because when I save options and then user enter command without them I can't guess from what host use config file (e.x. '.tddium' or '.tddium.localhost').

https://bugs.tddium.com/bugzilla/show_bug.cgi?id=619

@semipermeable
Copy link
Contributor

"set_params" is a confusing subcommand name.
The word "params" is generic, and can mean vastly different things depending on context.

How about instead:

tddium server  # displays the saved connection info
tddium server:set HOST [--port PORT] [--insecure]  # saves connection info
(port defaults to 443, insecure defaults to off)

@andriiNyzhnik
Copy link
Author

I have made changes. Now you can review please.

self.class.display
end

desc 'server:set HOST [PORT] [PROTO] [INSECURE]', "saves connection info"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This description does not match the implementation. The options in the description are all positional, but as you havr defined the thor task, they need to be passed with flags.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh...Options should be with flags, or without?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine either with flags or without.

The problem is that method_option in thor uses flags ( tddium server:set --host HOST [--port PORT] [--proto PROTO] [--insecure]) but the description on line 11 says that the command takes positional parameters without any flags (tddium server:set HOST [PORT] [PROTO] [INSECURE]).

What happens when you run:

bin/tddium server:set foo.example.com 2345 https false

I'm pretty sure it won't actually save any settings, because options will be empty.

@semipermeable
Copy link
Contributor

Needs a test for the server and server commands themselves.

@@ -270,6 +272,8 @@ module Process
Extract details of a session with `tddium describe <session_id>`.

EOF
OPTIONS_SAVED = 'Options have been successfully saved.'
NOT_SAVED_OPTIONS = 'You do not have file with options. Run `tddium server:add`.'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be "tddium server:set" ?

@andriiNyzhnik
Copy link
Author

added tests for server commands

let(:options){ {host: 'localhost', port: 3000, proto: 'http', insecure: true} }

it 'stores options and returns successfully message' do
subject.stub('server:set').with(options).and_return(self.class::Text::Process::OPTIONS_SAVED)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think is actually testing anything.

(that is: if you were to change the code in cli/commands/server.rb to be broken, this test would still pass)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but I have also test in spec/params_helper_spec.rb. I forgot to change file name and also there is one extra line in code(I will remove it)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with removing the test is that there's then nothing that actually validates the end-to-end functionality of setting the server.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Now I just need to add additional tests for ParamsHelper module (lib/tddium/cli/params_helper.rb)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A test for params_helper is not sufficient.

There needs to be a test that calls

 Tddium::TddiumCli.send("server:set", options)

And checks either that write_params was called, or that the setting file was actually written out.

@andriiNyzhnik
Copy link
Author

Changed tests. Please check.

end
rescue Errno::ENOENT => e
# when was called from class 'TddiumCli', return {} to use default options
if caller[1][/`([^']*)'/, 1] == '<class:TddiumCli>'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it better to test to see if Default::PARAMS_PATH exists with File.exists?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. I will also test presence of PARAMS_PATH constant

2014-08-05 21:14 GMT+03:00 wkj notifications@github.com:

In lib/tddium/cli/params_helper.rb:

@@ -0,0 +1,40 @@
+# Copyright (c) 2014 Solano Labs All Rights Reserved
+
+module ParamsHelper

  • include TddiumConstant
  • def load_params
  • begin
  •  File.open(Default::PARAMS_PATH, 'r') do |file|
    
  •    return JSON.parse file.read
    
  •  end
    
  • rescue Errno::ENOENT => e
  •  # when was called from class 'TddiumCli', return {} to use default options
    
  •  if caller[1][/`([^']*)'/, 1] == 'class:TddiumCli'
    

Is it better to test to see if Default::PARAMS_PATH exists with
File.exists?


Reply to this email directly or view it on GitHub
https://github.com/solanolabs/tddium/pull/60/files#r15830829.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think William is using "test" in the sense of "checking the condition" in the code itself.

i.e, instead of rescuing Errno::ENOENT, to use File.exists? explicity:

if File.exists?(Default::PARAMS_PATH) then
  JSON.parse(File.read(Default::PARAMS_PATH))
else
  nil
end

@andriiNyzhnik
Copy link
Author

Have made changes. Please check.

@wkj wkj force-pushed the bug_619_remember_options branch 3 times, most recently from 08e40cb to 4443f61 Compare August 25, 2014 22:07
@wkj wkj merged commit ff51c86 into master Aug 25, 2014
@andriiNyzhnik andriiNyzhnik deleted the bug_619_remember_options branch October 6, 2014 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants