@@ -42,7 +42,7 @@ module Code
4242 end
4343
4444 context "when config property does exist" do
45- with_file_and_content ( ".codeconfig" , "property = value" )
45+ with_file_and_content ( ".codeconfig" , "property = value\n " )
4646
4747 it "should not prompt the user for the property value" do
4848 expect ( System ) . not_to receive ( :prompt )
@@ -54,7 +54,80 @@ module Code
5454 end
5555 end
5656 end
57+ end
58+
59+ describe "get_master_branch_name" do
60+ context "when there is no previously stored property value" do
61+ with_file_and_content ( ".codeconfig" , "" )
62+ let ( :prompt_text ) { "You didn't set the name of the master branch. What is it ('master')?" }
63+
64+ it "asks the user for the property value" do
65+ expect ( System ) . to receive ( :prompt ) . with prompt_text
66+ Config . get_master_branch_name
67+ end
68+
69+ it "should return the value the user has provided" do
70+ allow ( System ) . to receive ( :prompt ) . with ( prompt_text ) . and_return ( "test-value" )
71+
72+ expect ( Config . get_master_branch_name ) . to eq ( "test-value" )
73+ end
74+
75+ it "should store the provided value into the file" do
76+ allow ( System ) . to receive ( :prompt ) . with ( prompt_text ) . and_return ( "test-value" )
77+ Config . get_master_branch_name
78+ file_content = File . read ".codeconfig"
79+ expect ( file_content . strip ) . to eq "master_branch = \" test-value\" "
80+ end
81+ end
82+
83+ context "when there is a previously stored property value" do
84+ with_file_and_content ( ".codeconfig" , "master_branch = \" value\" \n " )
85+ it "should not prompt the user for the property value" do
86+ expect ( System ) . not_to receive ( :prompt )
87+ Config . get_master_branch_name
88+ end
5789
90+ it "should return the stored property value" do
91+ expect ( Config . get_master_branch_name ) . to eq "value"
92+ end
93+ end
94+ end
95+
96+ describe "get_development_branch_name" do
97+ context "when there is no previously stored property value" do
98+ with_file_and_content ( ".codeconfig" , "" )
99+ let ( :prompt_text ) { "You didn't set the name of the development branch. What is it ('development')?" }
100+
101+ it "asks the user for the property value" do
102+ expect ( System ) . to receive ( :prompt ) . with prompt_text
103+ Config . get_development_branch_name
104+ end
105+
106+ it "should return the value the user has provided" do
107+ allow ( System ) . to receive ( :prompt ) . with ( prompt_text ) . and_return ( "test-value" )
108+
109+ expect ( Config . get_development_branch_name ) . to eq ( "test-value" )
110+ end
111+
112+ it "should store the provided value into the file" do
113+ allow ( System ) . to receive ( :prompt ) . with ( prompt_text ) . and_return ( "test-value" )
114+ Config . get_development_branch_name
115+ file_content = File . read ".codeconfig"
116+ expect ( file_content . strip ) . to eq "development_branch = \" test-value\" "
117+ end
118+ end
119+
120+ context "when there is a previously stored property value" do
121+ with_file_and_content ( ".codeconfig" , "development_branch = \" value\" \n " )
122+ it "should not prompt the user for the property value" do
123+ expect ( System ) . not_to receive ( :prompt )
124+ Config . get_development_branch_name
125+ end
126+
127+ it "should return the stored property value" do
128+ expect ( Config . get_development_branch_name ) . to eq "value"
129+ end
130+ end
58131 end
59132 end
60- end
133+ end
0 commit comments